How to fork a child process that listens on a different debug port than the parent

后端 未结 2 1588
挽巷
挽巷 2020-12-10 15:59

I am trying to use child_process.fork to spawn a process that breaks and listens on the V8 debug protocol.

However, I can\'t get the forked process to

相关标签:
2条回答
  • 2020-12-10 16:26

    Simple enough answer, found on this comment and with some help from #Node.js on Freenode:

    Just move the --debug-brk into the execArgv key of the options param to fork:

    // Excerpt:
    
    args = [
       '127.0.0.1'
      , 3030
      , 'api-testing'
    ]
    
    env = { 'DB_URI': 'mongodb://localhost/test' }
    
    child = fork(nodeModule, args, {
        env: env
      , execArgv: ['--debug-brk=6001']
    })
      .on('message', this.callback)
    

    execArgv is the array of parameters passed to the node process. argv is the set passed to the main module. There's a dedicated parameter to child_process.fork for argv, but execArgvs have to be placed within the opts param. This works, and in the child process we have:

    > process.execArgv 
    ["--debug-brk=6001"]
    > process.argv
    ["/usr/local/Cellar/node/0.10.13/bin/node" "/Users/dmitry/dev/linksmotif/app.js", "127.0.0.1", "3030", "api-testing"] 
    

    In summary

    Node.js consistently treats execArgv and argv as separate sets of values.

    0 讨论(0)
  • 2020-12-10 16:33

    Before to fork remove old debug-brk parameter :

    process.execArgv = process.execArgv.filter(function(o){ 
        var x = "--debug-brk"; 
        return o.substring(0, x.length) !== x
    });
    

    and add a new one:

    process.execArgv.push("--debug-brk=9999");
    
    0 讨论(0)
提交回复
热议问题