views:

97

answers:

3

I want my node.js server to run in the background, ie: when I close my terminal I want my server to keep running. I've googled this and came up with this tut, however it doesn't work as intended. So instead of using that daemon script, I thought I just used the output redirection (the 2>&1 >> file part), but this too does not exit (I get a blank line in my terminal, like it's waiting for output/errors).

I've also tried to put the process in the background, but as soon as I close my terminal the process is killed as well.

So how can I leave it running when I shut down my computer?

+1  A: 

This might not be the accepted way, but I do it with screen, especially while in development because I can bring it back up and fool with it if necessary.

screen
node myserver.js
>>CTRL-A then hit D

The screen will detach and survive you logging off. Then you can get it back back doing screen -r. Hit up the screen manual for more details. You can name the screens and whatnot if you like.

UltimateBrent
Maybe not the accepted way, but still very helpful, thanks!
Peter Kruithof
+2  A: 

use nohup

nohup node server.js &

SB
cool part to know: `nohup` stands for `no hangup` which comes from the old days, where you wanted you keep a process alive when you "hangup" your modem.
jAndy
A: 

Check out fugue! Apart from launching many workers, you can demonize your node process too!

http://github.com/pgte/fugue

Shripad K