如何在Visual Studio代码编辑器中确定群集服务器上的debugging模式
通常在Visual Studio Professional上我们可以在C#
#if DEBUG //doing something #else //Release mode doing something #endif
我的NodeJS服务器环境是集群,所以我需要检查debugging模式设置一些variables。
显然我不想把这个'#'来certificatedebugging模式,我只是想知道编辑器是否设置了一些process
variables来检查它。
我发现的一个很好的方法是在launch.json
文件中设置一个ENV
variables,如下所示:
{ "version": "0.1.0", "configurations": [ { "name": "Launch", "type": "node", "request": "launch", "program": "${workspaceRoot}/server.js", "stopOnEntry": false, "args": [], "cwd": "${workspaceRoot}", "runtimeExecutable": null, "runtimeArgs": [ "--nolazy" ], "env": { "NODE_ENV": "development", // Here's my change "IS_DEBUG": true }, "externalConsole": false, "sourceMaps": false, "outDir": null }] }
我已经包含一个名为IS_DEBUG
的新属性,并在ENV
中将其设置为true
,所以在我的服务器文件中,如果当前WORKER
是MASTER
,那么我将检查我的cluster
我还包括对此环境variables的检查,例如:
if (!kernel.isMaster() && !process.env.IS_DEBUG) { // If this is true I fork the process in cluster } // Else I go forward initializing my database and so on else { }
希望这有助于某人,让我知道如果你需要一些帮助。
- Node.js,node-inspector,JavaScript,Google Chrome:debugging工作stream程
- 很难在Node-Inspector中设置断点
- build议工作stream程和工具使用node.js
- 将node-webkit作为node.js应用程序运行
- 节点可执行文件无法在node-debugger pkg的primefaces中find
- 使用Passport.js的login系统始终执行“failureRedirect”(nodejs)
- 如何在WebStorm中debuggingReact Express Webpack应用程序
- closures时使用require时,不能在函数内部设置断点
- debugging器中的Webstorm 11