see below my code is very simple....it listens to a change on a database field in realtime-database.
const functions = require("firebase-functions");
var admin = require("firebase-admin");
exports.onActiveUpdate = functions.database
.ref("/profiles/users/{userId}/active")
.onUpdate((change, context) => {
//code here
return true;
});
I've tried to debug code locally with the following commands
firebase serve --only functions
firebase serve
firebase emulators:start
I always get the same message...
+ functions: Emulator started at http://localhost:5001
i functions: Watching "C:\code\rn\xs\fb_functions\functions" for Cloud Functions...
i functions[onActiveUpdate]: function ignored because the database emulator does not exist or is not running.
+ All emulators started, it is now safe to connect.
But then when I go to localhost:5001....all I see is a blank page with with {"status":"alive"} at the top.
Is this correct behavior? Thanks
You can run the emulator in inspect mode by running :
firebase emulators:start --inspect-functions
See what port it's listening to for debug (e.g. port 9229 ). If you are using VSCode, create(or update) a launch.json inside .vscode subdirectory of your project with the following content:
{
"configurations": [
{ "type": "node",
"request": "attach",
"name": "Debug",
"port": 9229
}
]
}
Then simply click on Debug icon in your VScode to connect to the running process. Now put some breakpoints in your functions code and invoke them through browser.
You can use https://github.com/GoogleChromeLabs/ndb to debug your http firebase functions.
Install it locally or globally and run your normal serve command with ndb:
ndb yarn serve
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With