Hosting Node.js app to DigitalOcean Server

Hosting Node.js application to Digital ocean Server is very easy and cheap in cost. You can begin with $5 basic program to host your first Node.js application live on Server. If you willing to buy one click here to get $10 discount on your first Server with Digital ocean.

What we’re going to do

In this tutorial we are going to host Node.js application in our Digital ocean Server. Our application will be Google recaptcha form using Node.js which we have covered in previous tutorial.

This tutorial will not cover each and every basic steps require such as buying server, setting up basic Nginx Server etc because I believe folks at Digital ocean have already written enough tutorial on it.

This tutorial only focuses on “Hosting Node.js application on a sub-domain”.


We are assuming you have your Digital ocean Server ready with Nginx installed or probably running your blog or website on same ( Like we are doing ). If you don’t have one and want to begin with, click here to buy your first digital ocean server with $10 discount.


You need few things ready before you move to next step, they are :

  • Git
  • Node and NPM.
  • PM2

Login to your Server and install them if you don’t have already, else move on to next section.

Install git

Run following command

sudo apt-get install git

Install latest Node.js

Run following command one after another.

curl -sL | sudo -E bash -
sudo apt-get install -y nodejs

Install PM2

Run following command to install PM2 globally.

npm i -g pm2

Setting up project

Clone your project from Github.

git clone

Switch to folder and install required dependencies.

cd google-racapcha-node && npm install

Hosting Node.js app

To host our application we need sub domain. Let’s create one from Digital ocean control panel.

Create sub domain

Go to digital ocean account then click on Networking and select View main domain.

Node.js hosting

Create new sub domain say google-recaptcha and put your IP in second box. For me it will be

Node.js hosting

Create Nginx config and add new block of this code into your config file. This probably be located in /etc/nginx/conf.d/ directory.

server {
    listen 80;


    root /usr/share/nginx/html/node;
    index index.html index.htm;

    client_max_body_size 10G;

    location / {
        proxy_pass http://localhost:--PORT--];
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;

Replace –PORT– with the port number on which Node.js app is running.

Deploy app

Go to Node project folder and start it with PM2.

pm2 start app.js

Node.js hosting
Restart nginx by using following command.

sudo service nginx restart

Visit the URL to view the app. Our app is here.

Hosting Node.js app

To learn how to develop Google reCAPTCHA in Node.js, visit this link.

Wrapping it up

This tutorial uses sub domain to deploy the Node.js application. However if you want to deploy on main domain, steps will be pretty much same.


Digital ocean is one of the cheapest and best hosting services for small-scale business. I am personally using it and I can recommend you this with confidence.