Switching NodeJs application to debug mode from within it's process

I have a NodeJs module "some-module" that I want to have installed globally so it can be run directly from the command line without the node executable prefix. ie: $> some-module [args] I would like one of those arguments to be --debug. The reasoning for this is that I don't want to require users of this module to install it to their local directory just to run node --debug-brk node_modules/some-module/[path to entry point] [args].

The NodeJs documentation states in it's advanced usages section on debugging (http://nodemanual.org/latest/nodejs_ref_guide/debugging.node.js.html)

The V8 debugger can be enabled and accessed either by starting Node.js with the --debug command-line flag or by signaling an existing Node.js process with SIGUSR1.

I tried doing this with:

process.kill(process.pid, 'SIGUSR1');

Which produced the error:

        throw e; // process.nextTick error, or 'error' event on first tick
Error: Unknown signal: SIGUSR1
    at EventEmitter.kill (node.js:366:17)
    at Object.<anonymous> (c:\dev\some-module\app.js:94:17)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Array.0 (module.js:479:10)
    at EventEmitter._tickCallback (node.js:192:40)

What do I need to do to get the running process switched to debug mode?

Also, I would like to debug the given application with node-inspector.

I'm not quite sure if I understood your question, but...

You can probably install an app globally and have it stop in a breakpoint using npm. In package.json put:

"scripts": {"start": "node --debug-brk some-module.js"},
"bin" : { "some-module" : "./some-module.js" },

Running npm start -g some-module will break at first line. You can then use node-inspector for debugging.

About the part with stopping from within the code, node has a build in debugger (which is quite rudimentary), but it allows this functionality. If you include somewhere in the code:


and run:

node debug some-module.js 

it will stop there in the debugger (note: this is not the same as node-inspector, i don't know if this can be achieved with node-inspector).

Don't really understand the reason why you're doing this, but hope this helps.