Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am doing Node.js development in Ubuntu and I'm curious if there is a way to quickly stop and restart a node server.

I run this command to start my app:

$ node app.js

When I make changes to app.js I have to restart the server. To stop it I have to use CTRL-C followed by UP and then enter to reissue the startup command.

Is there a faster way to do this? It doesn't seem like much until you're making many minor changes and needing to restart a lot.

share|improve this question
3 keystrokes is too much work? – glenn jackman May 25 '12 at 23:49
Nice straw man, but I didn't make that statement. I simply asked if there was a quicker way. – Chev May 26 '12 at 5:13

run it in cycle:

while : ; do node app.js ; done

so every time you'll hit CTRL-C it will end current node and start next one itself.

To end cycle just hold CTRL-C a while or kill from another shell or even close shell session.

share|improve this answer
This only works if SIGINT is trapped by the shell, which is not the case by default. Try it. – James Youngman May 25 '12 at 22:55
I tried it many times. It doesn't work with sleep or echo, but it does work with smth like ssh -N and node. – rush May 25 '12 at 23:03
Thanks for the suggestions :) – Chev May 26 '12 at 5:15

Many servers accept SIGHUP as a signal to reload their configuration. But if this will not work for you a simple alternative is to use Control-O instead of return. That executes this command and then fetches the next command from the history. Try it like this:

echo hello
echo world
[cursor-up twice]
[now press control-O until you get bored]

Works on Bash, I forget how widespread this feature is.

In this case for running node repeatedly you would just alternate Control-C and Control-O.

share|improve this answer
It will not work, cause u need to stop command at first (node doesn't end itself like echo in your example). – rush May 25 '12 at 22:58
That's why the instructions above mention that you need to press Control-C. – James Youngman May 26 '12 at 13:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.