Question

Need Help with Setting Up a Node.js App on DigitalOcean Droplet

Hi everyone,

I’m currently working on deploying a Node.js application to a DigitalOcean Droplet, and I’m running into a few challenges. I’ve created the droplet and installed Node.js using the official guide, but I’m having trouble getting the app to run in the background and ensuring it stays online after I disconnect from the SSH session.

Here’s what I’ve done so far:

  1. Created a Droplet with Ubuntu 20.04.
  2. Installed Node.js and npm.
  3. Uploaded my app files via SFTP.
  4. Tried running the app using node app.js, but the process stops when I disconnect.

What I need help with:

  • How can I ensure the app runs in the background, even after I close the SSH connection?
  • Should I use something like PM2 to manage the process, or is there a better solution for this?
  • Are there any other best practices for deploying Node.js apps on DigitalOcean?

Any help or advice would be greatly appreciated!

Thanks in advance for your time and support!

Best, Jsoon Hook!


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
February 16, 2025

Hi there,

Yes, you’ll want to use PM2 to keep your Node.js app running in the background and restart it if the server reboots. Here’s how to set it up on your DigitalOcean Droplet:

  1. Install PM2 globally:

    npm install -g pm2
    
  2. Start your app with PM2:

    pm2 start app.js --name my-node-app
    pm2 save
    pm2 startup
    

This keeps your app running even after you close SSH.

You can also use Git and GitHub to manage your code and deploy updates more easily instead of SFTP.

Also make sure to check out this guide for a more detailed setup: How to Use PM2 to Set Up a Node.js Production Environment.

Hope that this helps!

- Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

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.