How to restart a node.js server

后端 未结 9 1253
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-22 16:46

I\'ve installed and is running a node.js server on osx. I\'ve dled a chat module and is happily running it. I\'ve altered some pieces and need to restart the server to see t

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-22 17:21

    I had the same problem and then wrote this shell script which kills all of the existing node processes:

    #!/bin/bash
    echo "The following node processes were found:"
    ps aux | grep " node " | grep -v grep
    nodepids=$(ps aux | grep " node " | grep -v grep | cut -c10-15)
    
    echo "OK, so we will stop these process/es now..."
    
    for nodepid in ${nodepids[@]}
    do
    echo "Stopping PID :"$nodepid
    kill -9 $nodepid
    done
    echo "Done"
    

    After this is saved as a shell script (xxx.sh) file you might want to add it to your PATH as described here.

    (Please note that this will kill all of the processes with " node " in it's name except grep's own, so I guess in some cases it may also kill some other processes with a similar name)

提交回复
热议问题