Install the Firebase CLI
Learn how to install and initialize Firebase CLI.
Firebase command line interface (CLI)
Firebase command line interface (CLI) is used to interact with the Firebase web application. We will use it to interact with the application you created a short while ago.
Caution: As stated in the previous lesson, we are not going to follow the instructions in the Firebase wizard displayed in your web browser. We are currently working in the
enable-firebase-hosting
branch.
Installing the Firebase CLI
First of all, to keep the Firebase scripts and configuration files out of the main web service, let’s create a firebase folder at services/web/firebase
. We also need a
package.json
file where we can add NPM scripts to deal with Firebase. For this purpose, run the following commands:
mkdir services/web/firebase
cd $_
npm init
Provide the following values, with your name as the author:
package name: (firebase) web-firebase
version: (1.0.0)
description: The web service's Firebase project.
entry point: (index.js)
test command:
git repository:
keywords:
author: @<Your username>
license: (ISC)
In the services/web/firebase
directory, install the Firebase CLI with:
npm install -D firebase-tools
Why use npm install -D
not npm install -g
?
Using npm install -g to globally install NPM packages, such as the Firebase CLI, is a quick and convenient way to get started. However, it becomes an inconvenience for teams later. Here’s why.
With each globally installed NPM dependency, a project becomes less self-contained. There needs to be documentation somewhere that instructs others who work on a project to install all global NPM dependencies before they can work on a project. It is only a matter of time until that documentation is outdated.
Instead of -g, most of the successful web developers prefer -D. With -D, or –save-dev, the dependencies
become part of the package.json
file, and a simple npm install
ensures all dependencies the project needs are readily available!
As a nice side effect, dev dependencies can now easily be used in NPM scripts by referring to their name, such as firebase
in case of the Firebase CLI. We will leverage that in our web application.
Terminal
Get hands-on with 1400+ tech skills courses.