如何在Visual Studio代码编辑器中确定群集服务器上的debugging模式

通常在Visual Studio Professional上我们可以在C#

#if DEBUG //doing something #else //Release mode doing something #endif 

我的NodeJS服务器环境是集群,所以我需要检查debugging模式设置一些variables。

显然我不想把这个'#'来certificatedebugging模式,我只是想知道编辑器是否设置了一些processvariables来检查它。

我发现的一个很好的方法是在launch.json文件中设置一个ENVvariables,如下所示:

 { "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 ,所以在我的服务器文件中,如果当前WORKERMASTER ,那么我将检查我的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 { } 

希望这有助于某人,让我知道如果你需要一些帮助。