AskHandle

AskHandle Blog

How Do I Deploy a Node.js Application on DigitalOcean Droplet?

December 9, 2025Aria Singh3 min read

How Do I Deploy a Node.js Application on DigitalOcean Droplet?

Setting up and deploying a Node.js application on a DigitalOcean Droplet can seem challenging at first, but with the right steps, you can get your application running smoothly. This guide walks you through the complete process of deploying your Node.js application on a DigitalOcean Droplet.

Initial Setup Requirements

Before starting the deployment process, make sure you have:

  • A DigitalOcean account
  • A Node.js application ready for deployment
  • Basic command line knowledge
  • SSH key pair for secure access

Creating Your Droplet

The first step is creating a Droplet on DigitalOcean. Choose Ubuntu as your operating system, as it works well with Node.js applications. Select a plan that matches your needs - the $5/month basic Droplet works fine for small applications. Pick a datacenter region closest to your target users for better performance.

Accessing Your Droplet

After creating your Droplet, connect to it using SSH. Use this command in your terminal:

bash
1ssh root@your_droplet_ip

Replace 'your_droplet_ip' with the actual IP address of your Droplet.

Setting Up the Server Environment

Once connected, update your system and install the required packages:

bash
1apt update
2apt upgrade

Install Node.js and npm using these commands:

bash
1curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
2apt install -y nodejs

Verify the installation:

bash
1node --version
2npm --version

Transferring Your Application

You can transfer your application files to the Droplet using several methods. The most common way is using Git. Install Git on your Droplet:

bash
1apt install git

Then clone your repository:

bash
1git clone your_repository_url

If your code is not in a repository, you can use SCP to transfer files:

bash
1scp -r local_project_path root@your_droplet_ip:/root/app

Setting Up Your Application

Navigate to your application directory and install dependencies:

bash
1cd your_application_directory
2npm install

Create a production configuration file if needed. Test your application locally on the Droplet to make sure everything works:

bash
1node app.js

Using PM2 for Process Management

PM2 is a process manager for Node.js applications. It keeps your application running and manages crashes or system reboots. Install PM2:

bash
1npm install pm2 -g

Start your application with PM2:

bash
1pm2 start app.js

Set up PM2 to start on system boot:

bash
1pm2 startup systemd

Setting Up Nginx as Reverse Proxy

Install Nginx to handle incoming traffic:

bash
1apt install nginx

Create a new Nginx configuration file:

bash
1nano /etc/nginx/sites-available/your_app

Add this basic configuration:

nginx
1server {
2    listen 80;
3    server_name your_domain.com;
4
5    location / {
6        proxy_pass http://localhost:3000;
7        proxy_http_version 1.1;
8        proxy_set_header Upgrade $http_upgrade;
9        proxy_set_header Connection 'upgrade';
10        proxy_set_header Host $host;
11        proxy_cache_bypass $http_upgrade;
12    }
13}

Enable the configuration and restart Nginx:

bash
1ln -s /etc/nginx/sites-available/your_app /etc/nginx/sites-enabled/
2nginx -t
3systemctl restart nginx

Final Security Steps

Set up a firewall to protect your Droplet:

bash
1ufw allow OpenSSH
2ufw allow 'Nginx Full'
3ufw enable

Your Node.js application should now be running on your DigitalOcean Droplet. You can access it through your domain name or Droplet IP address. The application will stay running even if you log out of the server, and it will automatically restart if the server reboots or if the application crashes.

This setup provides a solid foundation for running your Node.js application in production. You can further improve it adding SSL certificates, monitoring tools