Since this post has gotten a lot of attention over the years, I've listed the top solutions per platform at the bottom of this post.
2>&1 >> file
Copying my own answer from How to run a Node.js application as its own process?
2015 answer: nearly every Linux distro comes with systemd, which means forever, monit, etc are no longer necessary - your OS already handles these tasks.
myapp.service file (replacing 'myapp' with your app's name, obviously):
[Unit] Description=My app [Service] ExecStart=/var/www/myapp/app.js Restart=always User=nobody Group=nobody Environment=PATH=/usr/bin:/usr/local/bin Environment=NODE_ENV=production WorkingDirectory=/var/www/myapp [Install] WantedBy=multi-user.target
Copy your service file into the
Start it with
systemctl start myapp.
Enable it to run on boot with
systemctl enable myapp.
See logs with
journalctl -u myapp
More details at: How we deploy node apps on Linux, 2016 edition