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.
Original post
If you simply want to run the script uninterrupted until it completes you can use nohup
as already mentioned in the answers here. However, none of the answers provide a full command that also logs stdin
and stdout
.
nohup node index.js >> app.log 2>&1 &
>>
means append to app.log
.2>&1
makes sure that errors are also send to stdout
and added to the app.log
.&
makes sure your current terminal is disconnected from command so you can continue working. If you want to run a node server (or something that should start back up when the server restarts) you should use systemd / systemctl.