2

I need to build a Cloud Function, so i am trying to set up a developer environment where i can test and debug a firebase function.

From the examples i saw, it all ends up setting up a nodejs node. Because i can't run the node directly, i need to use firebase CLI to start it, so i can't use any local debug.

The best thing i can come with is to put the code in html page and use the browser native debug, which is ok, but database handlers do not work.

Debugging on the server, looks to complicated for short cycles.

Is there a better way to debug it locally?

Update: database handlers work, but only while code is running. Can be triggered if the target object is changed during the same execution.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
MiguelSlv
  • 14,067
  • 15
  • 102
  • 169

1 Answers1

6

You seem to be confusing two pieces of your app:

  1. the web app, which is served from Firebase Hosting's servers, but runs in your user's browsers
  2. the functions, which run on Google Cloud's servers

To debug your web app locally, you can use firebase serve (similar to how you use firebase deploy to deploy it). Then open the site in your browser (it defaults to http://localhost:5000) and debug it using your browser's developer tools.

To debug your Cloud Functions for Firebase locally, there is an emulator. See the documentation for more info and the answer here: how to test Cloud Functions for Firebase locally on pc.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • you just have to use a lot of console logs for debugging, since you can't hit debuggers or break points. firebase serve mostly means you won't have to re-deploy to test every edit. . . – SeanMC Feb 21 '19 at 01:26
  • In the meantime you can add `--inspect-functions [port]` as an argument to `firebase emulator:start` which let's you attach your node-debugger the way you are used to. – bastianowicz Oct 22 '20 at 12:54