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...