From VS Code integrated terminal I run firebase serve --only functions,hosting
then in the debug tab I created the default launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}"
}
]
}
I want to debug the server side (functions/index.js) not the client side.
I've tried some configuration from https://code.visualstudio.com/docs/nodejs/nodejs-debugging with no luck.
How to debug Firebase functions in VS Code?
You can't debug Firebase functions without defining Firebase configuration variables first. Firebase CLI does it for you.
To debug you can try the same trick as you would do for Firebase functions unit test.
Add following lines to the index.js file before you call
admin.initializeApp(functions.config().firebase)
:You can debug Firebase functions now in a same way as any other google cloud function:
Install the Cloud Functions Emulator:
Start the Emulator:
Deploy your function:
You'll get output like this:
To debug using the standard Node.js Debugger type:
You'll get:
Now add following lines to your launch.json VS Code
Start debugging in your VS Code and trigger your function by calling URL you've got on step #3.
You can also trigger the function by typing
functions call helloWorldFunction
in the terminal.For more details refer to the instructions here Cloud Functions Local Emulator.