Question

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

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?


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.

Bobby Iliev
Site Moderator
Site Moderator badge
May 9, 2025
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

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

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

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.