在本地调试Firebase功能(node.js) [英] Debugging Firebase functions locally (node.js)
问题描述
下面看到我的代码非常简单....它侦听实时数据库中数据库字段的更改.
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;
});
我尝试使用以下命令在本地调试代码
Ive 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.
但是当我进入localhost:5001时....我看到的是空白页,顶部是 {"status":"alive"}
.
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
查看它正在侦听调试客户端的端口(例如端口9229).如果您使用的是VSCode,则在.vscode子目录
see what port it is listening for debug client (e.g. port 9229 ). if you are using VSCode have launch.json inside .vscode subdir
{
"configurations": [
{ "type": "node",
"request": "attach",
"name": "Debug",
"port": 9229
}
]
}然后只需单击VScode中的调试"图标即可连接到正在运行的进程.现在在您的函数代码中添加一些断点,并通过浏览器调用它们.
} then simply click on Debug icon in your VScode to connect to running process. now put some break point in your functions code and invoke them through browser.
这篇关于在本地调试Firebase功能(node.js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!