0
0
FirebaseHow-ToBeginner Ā· 3 min read

How to Use Firebase CLI: Commands and Examples

Use the firebase command-line tool to manage Firebase projects by running commands like firebase init to set up, firebase deploy to publish, and firebase serve to test locally. Install it with npm install -g firebase-tools and log in using firebase login.
šŸ“

Syntax

The basic syntax for Firebase CLI commands is firebase [command] [options]. Common commands include:

  • firebase login: Sign in to your Firebase account.
  • firebase init: Set up Firebase features in your project folder.
  • firebase deploy: Upload your project to Firebase hosting or functions.
  • firebase serve: Run your project locally for testing.

Options can modify commands, like --only hosting to deploy only hosting.

bash
firebase login
firebase init
firebase deploy
firebase serve
šŸ’»

Example

This example shows how to initialize a Firebase project, log in, and deploy hosting files.

bash
npm install -g firebase-tools
firebase login
firebase init hosting
firebase deploy --only hosting
Output
āœ” Success! Project initialized. āœ” Success! Hosting deployed to https://your-project-id.web.app
āš ļø

Common Pitfalls

Common mistakes include:

  • Not logging in before running commands, causing authentication errors.
  • Running firebase init in the wrong folder, which can misconfigure your project.
  • Forgetting to specify --only option when deploying specific features.
  • Not installing firebase-tools globally, leading to command not found errors.
bash
Wrong:
firebase deploy

Right:
npm install -g firebase-tools
firebase login
firebase deploy
šŸ“Š

Quick Reference

CommandDescription
firebase loginSign in to Firebase account
firebase initSet up Firebase project features
firebase deployDeploy project to Firebase
firebase serveRun project locally
firebase logoutSign out from Firebase account
āœ…

Key Takeaways

Install Firebase CLI globally with npm before use.
Always run firebase login to authenticate your account.
Use firebase init to configure your project folder.
Deploy your project with firebase deploy command.
Use --only option to deploy specific Firebase features.