Bobcares

WeSupport

Call Us! 1-800-383-5193
Call Us! 1-800-383-5193
Call Us! 1-800-383-5193

Need Help?

Emergency Response Time custom

Our experts have had an average response time of 11.06 minutes in March 2021 to fix urgent issues.

We will keep your servers stable, secure and fast at all times for one fixed price.

How to Deploy Node.js Application to DigitalOcean Server

by | Jan 24, 2021

Wondering How to Deploy Node.js Application to DigitalOcean Server? We can help you.

Node. js is used to build robust, scalable apps and has the capability to handle thousands of requests.

It is very efficient when it comes to web and enterprise applications that have a lot of input-output operations that query the database.

At Bobcares, we often get requests to deploy node.js application to Digital ocean droplets as a part of our Server Management Services.

Today let’s see the steps our Support Engineers follow to do the deployment.

How to Deploy Node.js Application to DigitalOcean Server

Applications are written in JavaScript and runs on platforms such as Linux, OS X, FreeBSD, and Windows. Node.js also helps to manipulate files programmatically with the built-in fs module.

Deploy Node.js Application to DigitalOcean Server

Though Node.js applications can be run at the command line we can also use it to automatically restart on reboot or failure of service.

The steps that ou Support Engineers follow are given below:

1. Building a simple NodeJS application:

Following are the commands for creating a sample node.js :

mkdir sample-nodejs-app

cd sample-nodejs-app

npm init -y

npm install express

touch index.js

After that open index.js and paste the following code into it:

// index.js

const express = require('express')
const app = express()

app.get('/', (req, res) => {
res.send('Hey, I\'m a Node.js app!')
})

app.listen(3000, () => {
console.log('Server is up on 3000')
})

We can start the application with the following command:

$ node index.js

And we can access it from http://localhost:3000.

We can see “Hey, I’m a Node.js app!” as output.

2. Creating a New Droplet

First, we will log in to the Digital Ocean account and create a new droplet (server).

We will select NodeJS from the One-click apps.

Next, we will choose the $10 plan which will allow us to install the NPM dependencies as it needs at least 1GB RAM for installing the dependencies.

We will set the datacenter region with the default one.

After that, we can either add a new SSh key or choose from the existing one we have added and then choose a hostname for the droplet and click the Create button.

The new server can be seen up and running on Ubuntu 16.04 and NodeJS version 6.11.2. We have to note down the IP address of the newly created server to access the server using it.

[Need assistance to create a new Droplet? We can help you!]

3. Creating Non-root User on the Digital Ocean Server.

First, we will to login to the server as root by using the IP address we got.

$ ssh root@SERVER_IP_ADDRESS

Next, we will create a new user:

$ adduser bob

To give the user bob administrative privileges we will use the below sudo command:

$ usermod -aG sudo bob

This will add the user bob to the sudoers group and will allow the user to run commands with superuser privileges.

4. Setup SSH Key For The Newly Created User:

For setting up the SSH key for bob we need to copy the public key to the new server.

We can use the following command:

$ cat ~/.ssh/id_rsa.pub

Then copy it to add the public key to a special file in bob’s home directory.

Before that switch to user bob from the root with the following command.

$ su - bob

Next, we need to create a new directory called .ssh and restrict its permission:

$ mkdir ~/.ssh
$ chmod 700 ~/.ssh

Inside the .ssh directory, we will create a new file called authorized_keys with the following command:

$ touch ~/.ssh/authorized_keys

Then open the file and paste the public key into the file and set the permissions right:

$ vim ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/authorized_keys

For returning to the root user we can use the following command:

$ exit

We can ensure access to the server with the new user by using the following command:

$ ssh bob@SERVER_IP_ADDRESS

5. Clone Node.js application to Digital Ocean Server

We will clone the node.js app on to the server directly in the user’s home directory (/home/bob) with the following command:

$ git clone https://github.com/ammezie/sample-nodejs-app.git

To install the dependencies give the following commands:

$ cd sample-nodejs-app
$ npm install

We will test the app to make sure everything is working as expected with the help of the following command:

$ node index.js

We can open a new terminal (without exiting the server) and enter the following command:

$ curl http://localhost:3000

The output “Hey, I’m a Node.js app!” can be seen.

Finally, the node.js application will be seen up and running.

[Need assistance to Deploy Node.js App? We are happy to help you!]

 

Conclusion

To conclude, we saw how to deploy node.js application to DigitalOcean Server.  Also, we saw the steps our Support Engineers follow to implement this.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Bobcares

Use your time to build great apps. Leave your servers to us.

Managing a server is time consuming. Whether you are an expert or a newbie, that is time you could use to focus on your product or service. Leave your server management to us, and use that time to focus on the growth and success of your business.

TALK TO US Or click here to learn more.
Bobcares

Use your time to build great apps. Leave your servers to us.

Managing a server is time consuming. Whether you are an expert or a newbie, that is time you could use to focus on your product or service. Leave your server management to us, and use that time to focus on the growth and success of your business.

TALK TO US Or click here to learn more.

Categories:

Tags:

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF