Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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. –  Alex Ford May 26 '12 at 5:13
add comment

2 Answers

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 :) –  Alex Ford May 26 '12 at 5:15
add comment

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
1  
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
add comment

Your Answer

 
discard

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.