Starting Node.js server without console

Okay, so this is probably a very noob question, but I'm just starting with node.js and I've noticed that all the tutorials tell you to do something like this:

app.listen(3000);
console.log('Listening on port 3000');

to start your server. This works fine for testing on a local host, but it requires me to use the console to start the server by typing node server.js

In a production enviroment how do you manage this? I'm sure I don't have to use a program like putty to tunnel in and start the server. Can someone explain this to me? I'm currently using node.js latest build with express web framework.

Thanks

Unless you use some fancy platform like Amazon's AWS Elastic Beanstalk or Heroku, in a production environment you will still have to have some sort of console access (SSH) to log in the server, and upload and start your application. You need to ensure the app runs continuously as a background service, and gets restarted if it crashes.

There are utilities for node that help you with that, like forever.

With forever, you would do something like this:

$ git clone git://gitserver:myapp.git
$ cd myapp
$ npm install
$ sudo npm install -g forever
$ forever start server.js

This leaves server.js running as a daemon in the background and you can close SSH. To see the daemons running and the logs you can run:

$ forever list
$ forever logs 0

The app will still run on port 3000, so you may want to configure a reverse proxy server to redirect port 80, like nginx, for example.

Try using screen if you're using Ubuntu or some other variation of Linux.

If you're connected via SSH, you would do screen node server.js and then you would press [Control] + [A] and then [Control] + [D]. You would pop right back out at the console and you can exit without stopping the node process.