Run Functions Locally

You can deploy and run functions locally using the Firebase CLI. This allows you to test your functions before deploying to production.

To use this feature, firebase-tools must have minimum version 3.8.0, and firebase-functions SDK must have minimum version 0.5.7. To update both, run the following commands in the functions/ directory for your project:

npm install --save firebase-functions
npm install -g firebase-tools

To run functions locally, use firebase serve:

firebase serve --only functions # to only emulate functions
firebase serve --only functions,hosting # to emulate both functions and hosting

This command outputs a URL where you can view or test your Firebase hosting content and HTTP functions.

Logging

The Firebase CLI streams logs from your functions to the terminal window that it's running in. It displays all output from console.log(), console.info(), console.error(), and console.warn() statements inside your functions.

Environment configuration

The Firebase CLI will emulate functions.config().firebase with the appropriate Firebase project config values. However, if your functions rely on other custom environment config variables, you'll need to create a .runtimeconfig.json file within your functions/ directory. If you are using firebase-tools v3.9.1 or above, you can generate this file by running:

firebase functions:config:get > .runtimeconfig.json

Afterwards, functions/.runtimeconfig.json should look similar to:

{
  "keys": {
    "stripe": "STRIPE_KEY",
    "github": "GITHUB_KEY"
  }
}

Send feedback about...

Need help? Visit our support page.