Get started with Cloud Functions

To get started setting up Cloud Functions for your Firebase project, install the Firebase CLI, and set up project files on your local machine.

Install the Firebase CLI

The Firebase CLI (Command Line Interface) requires Node.js and npm, which you can install by following the instructions on Installing Node.js also installs npm.

The Firebase CLI requires Node.js version 6.3.1 or greater. Once you have Node.js and npm installed, install the Firebase CLI via npm:

npm install -g firebase-tools

This installs the globally available firebase command. To update to the latest version, re-run the same command.

If the command fails, you may need to change npm permissions.

Initialize your project

The firebase command line tool builds the necessary project structure and files, and optionally installs Node.js dependencies with npm.

To initialize your project:

  1. Run firebase login to log in via the browser and authenticate the firebase tool.
  2. Go to your Firebase project directory.
  3. Run firebase init functions. The tool gives you an option to install dependencies with npm. It is safe to decline if you want to manage dependencies in another way.

After these commands complete successfully, your project structure looks like this:

 +- .firebaserc    # Hidden file that helps you quickly switch between
 |                 # projects with `firebase use`
 +- firebase.json  # Describes properties for your project
 +- functions/     # Directory containing all your functions code
      +- package.json  # npm package file describing your Cloud Functions code
      +- index.js      # main source file for your Cloud Functions code
      +- node_modules/ # directory where your dependencies (declared in
                       # package.json) are installed

You are now ready to try the tutorial on how to create and deploy your first Cloud Functions. Or, you could review basics like handling dependencies before diving into specific event handling such as Realtime Database triggers or reviewing the API reference.

Send feedback about...

Need help? Visit our support page.