且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在nodejs中以编程方式检测调试模式?

更新时间:2023-12-04 21:19:34

NodeJS在调试模式下运行时创建一个 v8debug 全局对象: node debug script.js

NodeJS creates a v8debug global object when running in debug mode: node debug script.js

所以,一个可能的解决方案是:

So, a possible solution would be:

var debug = typeof v8debug === 'object';

对于我的用例,我使用它是因为我我想要避免传递环境变量我的主节点进程启动子节点进程,我想要一个节点调试mainScript.js 还可以触发儿童的调试模式(再次,没有向子进程传递env变量)

For my use case, I use it because I want to avoid passing environment variables. My main node process starts child node processes and I want a node debug mainScript.js to trigger debug mode for children as well (again, without passing env variables to child processes)