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 the effects.
I only know how to restart by closing the terminal window and then reopneing it and then running node chatdemo.js again.
Any way to restart without closing terminal?
Thanks.
If it's just running (not a daemon) then just use Ctrl-C
.
If it's daemonized then you could try:
$ ps aux | grep node
you PID 1.5 0.2 44172 8260 pts/2 S 15:25 0:00 node app.js
$ kill -2 PID
Where PID
is replaced by the number in the output of ps
.
During development the best way to restart server for seeing changes made is to use nodemon
npm install nodemon -g
nodemon [your app name]
nodemon will watch the files in the directory that nodemon was started, and if they change, it will automatically restart your node application.
Check nodemon git repo: https://github.com/remy/nodemon
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With