It's Known that you have to test your functions first, before deploying them to firebase to avoid loops and unwanted behavior. I need to run a local environment to test it first, How can I do that?
CodePudding user response:
//How to Debug Firebase Functions locally
1 - Start EMU for debugging functions(required Java installed) firebase emulators:start --inspect-functions
2 - Connect Webstorm Debugger Edit Run/Debug configurations -> Attach to Node/Chrome (select the correct port(just in case))(9229 by default)
3 - Run ngrok and server the functions port (http://127.0.0.1:5001/sexybarbiegirl-f6068/us-central1/app) | here | ./ngrok http 127.0.0.1:5001
4 - Finish output
|ngrok tunnel| |rest of your API endpoints|
http://4386-2600-8801-192-4500-4dcd-e70f-e09f-63cb.ngrok.io/wherever-you-app-is/app
CodePudding user response:
To run Firebase Firestore Cloud Functions locally and debug them, you can use the firebase emulators:start
command, this will allow you to test your functions on your local machine, using the same runtime and dependencies as the production environment.
To debug your functions, you can use the console.log
method, and use the debug command in the Cloud Functions shell to attach a debugger to the running function. This will allow you to step through your code, set breakpoints, and inspect variables, which can help you identify and fix any issues with your functions.
$ firebase emulators:start
# Output
i emulators: Starting emulators: functions, firestore, hosting
i functions: Using Node.js version: 12
i functions: Emulator started at http://localhost:5001
i firestore: Emulator started at http://localhost:8080
i hosting: Emulator started at http://localhost:5000
$ firebase functions:shell
# In the Cloud Functions shell
> debug functions/helloWorld
# Output
[debug] functions:helloWorld: Listening on port 5001.
[debug] functions:helloWorld: Stopped the emulator.
A bit more documentation: https://firebase.google.com/docs/emulator-suite