Baxter
Baxter

Reputation: 3085

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?

Upvotes: 3

Views: 4323

Answers (2)

MateodelNorte
MateodelNorte

Reputation: 1280

Looks like you're also setting

.use(cluster.repl('/Users/testuser/work/1test/test.sock'))

which probably doesn't exist on your linux server.

Upvotes: 0

Lalit Kapoor
Lalit Kapoor

Reputation: 400

try forever.

npm install -g forever

https://github.com/indexzero/forever

Upvotes: 4

Related Questions