How to kill an open process on node.js?

前端 未结 5 1620
滥情空心
滥情空心 2020-12-07 16:53

I\'m trying to set up a build-system for Node.js on sublime, so I can press F7 to call \"node\" on the openned file. The problem is that the process is then open forever, so

5条回答
  •  旧时难觅i
    2020-12-07 17:38

    From within Node.js:

    var die = function(quitMsg)
    {
        console.error(quitMsg)
        process.exit(1);
    } 
    
    die('Process quit');
    

    There are certain methods available for exiting that are only available for POSIX (i.e. not Windows) that will exit a process by its process id.

    Also, note that you might be able to send a kill() signal using this method, which does not say it isn't available for Windows:

    process.kill(pid, [signal])
    

提交回复
热议问题