keep a node js file running

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

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.


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.