I’m running a Node.js app on a DigitalOcean Droplet (Ubuntu), and every now and then the app crashes due to some unhandled error. I’d like to make sure the app restarts automatically if that happens.
What’s the best way to set this up? Should I use a process manager or something built into the OS? Or maybe Docker?
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!
Accepted Answer
Hey!
For me the best way to keep your Node.js app running is to use PM2, it is a process manager made for Node apps. It takes care of restarts, logs, and even starts your app again if the server reboots.
Quick setup:
npm install -g pm2
pm2 start app.js
pm2 startup
pm2 save
That’s it, it’s solid and easy to manage.
Here’s a full guide from DigitalOcean if you want to dig deeper: 👉 How To Set Up a Node.js Application for Production on Ubuntu
If you’re planning to scale things or want better portability and isolation, you might also want to look into Docker as you mentioned. It makes your app super easy to deploy across different environments and helps avoid the classic “works on my machine” issue.
Here is a free ebook for beginners: 📘 Introduction to Docker
- Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.