Stop node.js program from command line

后端 未结 19 2301
无人及你
无人及你 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:01

    I ran into an issue where I have multiple node servers running, and I want to just kill one of them and redeploy it from a script.

    Note: This example is in a bash shell on Mac.

    To do so I make sure to make my node call as specific as possible. For example rather than calling node server.js from the apps directory, I call node app_name_1/app/server.js

    Then I can kill it using:

    kill -9 $(ps aux | grep 'node\ app_name_1/app/server.js' | awk '{print $2}')

    This will only kill the node process running app_name_1/app/server.js.

    If you ran node app_name_2/app/server.js this node process will continue to run.

    If you decide you want to kill them all you can use killall node as others have mentioned.

提交回复
热议问题