Stop node.js program from command line

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

    You can use fuser to get what you want to be done.

    In order to obtain the process ids of the tasks running on a port you can do:

    fuser <>/tcp
    

    Let's say the port is 8888, the command becomes:

    fuser 8888/tcp
    

    And to kill a process that is running on a port, simply add -k switch.

    fuser <>/tcp -k
    

    Example (port is 8888):

    fuser 8888/tcp -k
    

    That's it! It will close the process listening on the port. I usually do this before running my server application.

提交回复
热议问题