Running Scheduled Firebase Functions Locally

Friday, May 15, 2020

By Etin Obaseki

TL;DR Use $ firebase functions:shell and then type in the name of your function (tab autocomplete is available) along with any arguments you need to pass and press enter. You receive the output to the console.

While developing Firebase Functions, we need to run them locally to ensure that everything works as we might expect before we deploy the function to the cloud.

For HTTP Functions, it’s a straightforward process to run $ firebase serve in the terminal and then visit the browser.

Firebase Scheduled Functions can have one of several triggers (similar to HTTP Functions that are triggered by a HTTP Request).

The problem is that we often cannot set up the trigger for Scheduled Functions the way we can for HTTP Functions.

For example, with the PubSub triggers it would be impractical to try to set up a pubslisher-subscribe system on our local environments and test that our functions run every minute as prescribed.

We’ll instead leave that to the Firebase team. Instead, we want to test that our functions executes as it should.

Use $ firebase functions:shell and then type in the name of your function (tab autocomplete is available) along with any arguments you need to pass and press enter. You receive the output to the console.