Report this

What is the reason for this report?

How to Automatically Restart a Crashed App on a DigitalOcean Droplet?

Posted on May 9, 2025

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.
0

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.