I am trying to use child_process.fork to create a process that interrupts and listens for the V8 debugging protocol.
However, I cannot force the forked process to listen on a port other than the parent process. Assuming the parent process is listening on 6000 , the child process is also trying to listen on port 6000 :
Could not open socket on port 6000, waiting for 1000 ms before retrying
Here is my code:
// `test.js`, invoked as `node --debug-brk=6000 test.js` var nodeModule, args, env, child nodeModule = path.normalize(path.join(__dirname, '..', 'app.js')) args = [ '--debug-brk=6001' , '127.0.0.1' , 3030 , 'api-testing' ] env = { 'DB_URI': 'mongodb://localhost/test' } child = require('child_process') .fork(nodeModule, args, {env: env}) .on('message', callback)
As you can see, I am trying to listen to the forked process on port 6001 , but the child process is trying to listen to port 6000 , which is used by the parent.
How can I make a child process listen on port 6001 or some other free port?
There are several topics on this subject. For example:
- How to debug a Node.JS child forked process?
- Debugging Node.js processes using cluster.fork ()
But:
- These threads are for
cluster forking. - Refer to
execArgv , which looks like it was undocumented for process and still not documented for cluster .
Dmitry Minkovsky
source share