Running the application

Running the application on the command line using node, like we have been doing until now, works during development; but on a production server where we connect remotely, it is generally not feasible or advisable to keep the console running. There are two ways to handle this, either we run node as a background process redirecting all console output to a file or we run it in a persistent console, to which we can reconnect, using screen or byobu.

To run node as a background process, like any other process on Linux, we will use the & operator and to make sure that it keeps running even after we log out, we will use nohup:

$ nohup npm start 2>&1 >> npmout.log &

The preceding command will redirect the stdout and stderr commands to npmout.log and will put the npm process in the background.

Another option is to run node on a long-lasting console, using utilities such as screen or byobu. To use this, start screen and then run your application, as shown here:

$ screen
$ npm start

Now we can detach from this screen by using Ctrl +a and then hitting d. This will drop us to the default shell. We can then disconnect. When we connect back to the server, to see the server output, we can attach back to the screen by using the following command:

$ screen -r
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset