Stop node.js program from command line

后端 未结 19 2315
无人及你
无人及你 2020-11-29 14:51

I have a simple TCP server that listens on a port.

var net = require(\"net\");

var server = net.createServer(function(socket) {
    socket.end(\"Hello!\\n\"         


        
19条回答
  •  没有蜡笔的小新
    2020-11-29 15:10

    If you want to stop your server with npm stop or something like this. You can write the code that kill your server process as:

    require('child_process').exec(`kill -9 ${pid}`)
    

    Check this link for the detail: https://gist.github.com/dominhhai/aa7f3314ad27e2c50fd5

提交回复
热议问题