Cloud Functions Emulator

Yusinto Ngadiman
jsdownunder
Published in
2 min readApr 13, 2018

Gettin jiggy with Google’s faas

Cloud functions are cool because now you just write code instead of worrying about deploying that code. Google has an emulator which lets you write your function, run it locally, repl the hell out of it, and then and only then when you are finished, deploy it! Let’s check it out.

1. Install functions emulator

yarn global add @google-cloud/functions-emulator

After installation is complete, start the emulator:

functions start

2. Write your code

Create a temp dir, cd into it and create a single file called index.js containing your code. If you are lazy you can just git checkout my demo repo.

mkdir functions-emulator-demo && cd functions-emulator-demo
index.js containing your functions code

Some notes:

  • By default the emulator looks for an index.js file in the current working directory. You can specify a different directory by using the — local-path option.
  • Ensure your module.exports refers to an object keyed with your function names.

3. Deploy your code to the emulator and run

functions deploy greet --trigger-http

Then run your function:

functions call greet

Useful Tips

Tip #1: See console logs

functions logs read

Tip 2: Debug using inspector

You can step through your functions code in many ways, but I’ll show you how to use the chrome devtools here. First, you need to run your function in inspection mode:

functions inspect greet

Then open chrome, type chrome://inspect and click on the inspect link on your target. It’s easier to visually demo this, so check out the video below.

Debug cloud functions on the emulator with chrome devtools

Conclusion

Google cloud functions emulator kicks ass! Happy coding.

--

--

Yusinto Ngadiman
jsdownunder

Tea lover. Frontend engineer at Qantas. Views and opinions are my own.