Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js, express and cluster

I have setup a test of a Node.js server but how is the server best launched?

My strategy for now is to use cluster (http://learnboost.github.com/cluster/). This mostly works really nice. I have the following setup in my app.js file (created with express):

cluster(app)
.use(cluster.reload())
.use(cluster.reload('views', {extensions: ['.js', '.ejs']}))
.use(cluster.logger('logs'))
.use(cluster.stats())
.use(cluster.repl('/Users/testuser/work/1test/test.sock'))
.use(cluster.debug())
.use(cluster.pidfiles())
.use(cluster.cli())
.listen(3000);

It works on my Mac when i test locally. I launch it with the command

nohup node app.js &

But when I run on Linux and detach from the terminal the master dies - the working threads are still working. On the Mac it runs even when I close the terminal.

I read that it might be necessary to change the user, this can apparently be done in cluster with: .set('user', 'rambo')

Does anyone have a "best practice" for launching node.js as a "Daemon" with cluster so you can detach the terminal?

If I change the user who should I be logged in as when I launch?

Should I use a program such as screen to detach from the terminal without killing any processes?

like image 818
Baxter Avatar asked Mar 07 '26 14:03

Baxter


1 Answers

try forever.

npm install -g forever

https://github.com/indexzero/forever

like image 167
Lalit Kapoor Avatar answered Mar 09 '26 03:03

Lalit Kapoor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!