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!
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.
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:
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