firebase-basics

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Prerequisites

前置条件

Node.js and npm

Node.js 和 npm

To use the Firebase CLI, you need Node.js (version 20+ required) and npm (which comes with Node.js).
Recommended: Use a Node Version Manager (nvm) This avoids permission issues when installing global packages.
  1. Install nvm:
    • Mac/Linux:
      curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
    • Windows: Download nvm-windows
  2. Install Node.js:
    bash
    nvm install 24
    nvm use 24
Alternative: Official Installer Download and install the LTS version from nodejs.org.
Verify Installation:
bash
node --version
npm --version
使用Firebase CLI需要Node.js(要求版本20+)和npm(随Node.js一同安装)。
推荐:使用Node版本管理器(nvm) 这可以避免安装全局包时出现权限问题。
  1. 安装nvm:
    • Mac/Linux:
      curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
    • Windows:下载nvm-windows
  2. 安装Node.js:
    bash
    nvm install 24
    nvm use 24
替代方案:官方安装包nodejs.org下载并安装LTS版本。
验证安装:
bash
node --version
npm --version

Core Workflow

核心工作流程

1. Installation

1. 安装

Install the Firebase CLI globally via npm:
bash
npm install -g firebase-tools
Verify installation:
bash
firebase --version
通过npm全局安装Firebase CLI:
bash
npm install -g firebase-tools
验证安装:
bash
firebase --version

2. Authentication

2. 身份验证

Log in to Firebase:
bash
firebase login
  • This opens a browser for authentication.
  • For environments where localhost is not available (e.g., remote shell), use
    firebase login --no-localhost
    .
登录Firebase:
bash
firebase login
  • 这会打开浏览器进行身份验证。
  • 对于无法访问localhost的环境(如远程shell),使用
    firebase login --no-localhost

3. Creating a Project

3. 创建项目

To create a new Firebase project from the CLI:
bash
firebase projects:create
You will be prompted to:
  1. Enter a Project ID (must be unique globally).
  2. Enter a display name.
通过CLI创建新的Firebase项目:
bash
firebase projects:create
系统会提示您:
  1. 输入项目ID(必须全球唯一)。
  2. 输入显示名称。

4. Initialization

4. 初始化

Initialize Firebase services in your project directory:
bash
mkdir my-project
cd my-project
firebase init
The CLI will guide you through:
  • Selecting features (Firestore, Functions, Hosting, etc.).
  • Associating with an existing project or creating a new one.
  • Configuring files (firebase.json, .firebaserc).
在您的项目目录中初始化Firebase服务:
bash
mkdir my-project
cd my-project
firebase init
CLI会引导您完成以下操作:
  • 选择功能(Firestore、Functions、Hosting等)。
  • 关联现有项目或创建新项目。
  • 配置文件(firebase.json、.firebaserc)。

Exploring Commands

探索命令

The Firebase CLI documents itself. Instruct the user to use help commands to discover functionality.
  • Global Help: List all available commands and categories.
    bash
    firebase --help
  • Command Help: Get detailed usage for a specific command.
    bash
    firebase [command] --help
    # Example:
    firebase deploy --help
    firebase firestore:indexes --help
Firebase CLI自带文档指引。指导用户使用帮助命令来了解更多功能。
  • 全局帮助:列出所有可用命令和分类。
    bash
    firebase --help
  • 命令帮助:获取特定命令的详细用法。
    bash
    firebase [command] --help
    # 示例:
    firebase deploy --help
    firebase firestore:indexes --help

SDK Setup

SDK配置

Detailed guides for adding Firebase to your app:
  • Web: See references/web_setup.md
将Firebase集成到应用中的详细指南:
  • Web:查看references/web_setup.md

Common Issues

常见问题

  • Permission Denied (EACCES): If
    npm install -g
    fails, suggest using a node version manager (nvm) or
    sudo
    (caution advised).
  • Login Issues: If the browser doesn't open, try
    firebase login --no-localhost
    .
  • 权限被拒绝(EACCES):如果
    npm install -g
    失败,建议使用Node版本管理器(nvm)或
    sudo
    (需谨慎使用)。
  • 登录问题:如果浏览器无法打开,尝试使用
    firebase login --no-localhost