keep a node js file running

Posted March 29, 2019 6k views
Node.jsUbuntu 16.04

Hi all , i have writting my little node js file that run mysql querys for me what i need to know is how i keep this running when i am not connected as it will need to do this when i am not at the computer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer


There are several ways to go about this. The dirtiest way (in my opinion) is simple but not fault tolerant, and it uses a screen session. So, for example, if this were Debian/Ubuntu:

apt-get update
apt-get install screen -y
screen -S nodeapp
node app.js

Then CTRL+A followed by CTRL+D to detach from the screen session. This persists when you log out of your SSH session.

However, I recommend something a bit more powerful if you’re up for it. You can use PM2 as a manager for this, and we have a tutorial here:

Obviously you don’t need all of that tutorial, but you should be able to extract what is relevant to you.


by Jim Cassidy
Use these instructions to setup an Ubuntu server to run Node.js applications, including apps based on Express, Geddy, or Sails. This will help you avoid some security mistakes and will provide some surprising benefits.