Cloud Functions Local Emulator

The Cloud Functions Emulator is a Node.js application that implements the Cloud Functions REST and gRPC APIs, and includes a command line interface for managing the application. The Emulator allows you to deploy, run, and debug your Cloud Functions on your local machine before deploying them to the production Cloud Functions service.

The Emulator is an Open Source project, hosted on GitHub.

Getting Started

The Cloud Functions Emulator is distributed as a standard NPM package, so you can install it with a standard npm install command:

npm install -g @google-cloud/functions-emulator

Or you can use Yarn if you prefer:

yarn global add @google-cloud/functions-emulator

Using the Emulator

After installation you should have a global functions command available. To verify this, type the following command in a terminal window:

functions --help

If your terminal already has a conflicting functions command, the Emulator's command line interface can also be accessed using the functions-emulator command.

You can get help on any command by running the following:

functions  --help

Starting and Stopping the Emulator

Before you can deploy a function, you need to start the Emulator as follows:

functions start

You stop the Emulator by calling stop:

functions stop

If the Emulator fails to stop for any reason, you can use the kill command to forcibly terminate the underlying process:

functions kill

Deploying Functions to the Emulator

Deploying functions to the Emulator uses the same syntax as the gcloud command-line tool.

For example, you would deploy an HTTP function to the Emulator as follows:

functions deploy helloWorld --trigger-http

This deploys the function found in the current working directory. To deploy from a different location, use the --local-path flag:

functions deploy helloWorld --trigger-http --local-path=~/myFunction

Calling Functions in the Emulator

To invoke a function deployed to the Emulator, use the call command:

functions call helloWorld

To send a payload to the function, use the --data flag:

functions call helloWorld --data='{"message":"Hello World"}'

You can also invoke functions deployed with an HTTP trigger by sending a request to the URL provided after deployment.

Viewing Logs

Logs emitted from your function are written to the local file system. You can view them via the logs command:

functions logs read

You can also view the log file itself on the local file system, and can determine its location by issuing a status command:

functions status

Debugging with the Emulator

You can debug your functions running in the Emulator using either the standard Node.js Debugger or the new V8 Inspector integration. To debug using the standard Node.js Debugger, run the following command:

functions debug helloWorld

To debug using the new V8 Inspector integration, run the following command:

functions inspect helloWorld

You can also configure the Debugger's port and/or force the function to pause execution until you attach to the Debugger. Run either of the following commands for details:

functions debug --help

or

functions inspect --help

Once a deployed function has entered debug mode, you can attach any standard Node.js debugging client to its debugger.

To take your function out of debug mode, run the following:

functions reset helloWorld

or to restart the function and keep its debugging settings, run the following:

functions reset helloWorld --keep

Run functions reset --help for details.

You can find more detailed documentation on how to debug with the Emulator with Chrome Devtools, Visual Studio Code, or Webstorm on the GitHub page.

Getting Help

To view detailed Emulator help, add the --help flag to any command:

functions --help

or

functions <command> --help

More detailed documentation is also available on GitHub, where you can also view and/or file any issues.

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Cloud Functions Documentation