Express is one of the best backends for building the REST API. But how do you use the backend created on a cloud server to make it work?

Yes, here we discuss the steps needed to deploy an express backend on a cloud server.

We connect the domain name to our REST API (https://api.mynewblog33.com) and install an SSL certificate to protect it.

I assume you’ve already created an express backend to use and pushed it into GitHub or Bitbucket. Otherwise read my previous article, which you can see below.

How to create a simple REST-API with node/pressure

Well, the backend for express access is ready, and now we need a cloud server to deliver this application.

I also assume you already have the cloud server with you. You can also create your own cloud server in Vultr, see the following article

How can you configure your own cloud server on Vultr (VC2)?

You can choose any operating system on the cloud server, but I prefer Ubuntu. All commands in this article work perfectly in Ubuntu.

So, after configuring the cloud server, you get the terminal.

We can use this terminal to configure our server to run the Express application.

1. Cloud ServerConfiguration

In order to run our Express application on the Ubuntu server, we need to install a number of tools and configure them properly.

1.1 Installing nodes and npm

Since Express is the framework for Node.js, it is necessary to install Node.js and npm on our server.

Below are the commands to install the latest version of Nodejs.

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash –
sudo apt – get installation -y nodejs

1.2 PM2 assembly

In developing the Express backend we used Nodemon, a tool that helps to develop node.js based applications by automatically restarting the application on the node when it detects changes in a file in the directory.

But on our server we use pm2 instead of nodemon, which allows our application to run in the background.

Set pm2 with the following command.

npm setting pm2 -g

Launch another one that will help you run your pm2 applications, even after a restart of our server.

pm2 Start Ubuntu

1.3 Firewall configuration

We need to activate the firewall. The following command contains a firewall.

sudo ufw

Now configure the firewall to allow access via HTTP, HTTPS and SSH.

sudo ufw let http
sudo ufw let https
sudo ufw let ssh

1.4 Setting the NGINX

NGINX is a free, open source, high performance HTTP server and reverse proxy. So install NGINX to configure a reverse proxy for our application.

sudo apt-get install nginx

1.5 Creating an NGINXConfiguration

We now need to change the default configuration of NGINX and add our own. So use the NANO editor to open the default configuration file.

sudo nano /etc/nginx/sites available/standard

Open the configuration in the Nano Editor. Delete all lines with the backspace key and add the following configuration.

server {
listen 80 default_server;
listen [:]:80 default_server;
root /var/www/html;
index.html index.html.nginx-debian.html;
server_name _;
location / {
try_files $uri/ =404;
}
}.

Use the shortcut keys below to save the file in Nano Editor.

Advice from the nano editor:-
1. Ctrl + O (tender)
2. Enter
in 3. Ctrl + x (output)

Create a MyBlog.conf file in the directory available on the site describing the configuration of the application we are going to implement.

sudo nano /etc/nginx/sites-available/MyBlog.conf

Add the configuration details as shown below. You need to change the server name with your domain. This configuration directs api.mynewblog33.com to the pm2 application running on our server on port 3001.

Server {
root /var/www/html;
index.html index.html.nginx-debian.html;
server_name api.mynewblog33.com;
location / {
proxy_pass http://localhost:3001;
proxy_http_version 1.1 ;
proxy_set_header Upgrade $http_upgrade ;
proxy_set_header Connection ‘upgrade’ ;
proxy_set_header Host $host ;
proxy_cache_bypass $http_upgrade ;
}
}.

Use the shortcut keys below to save the file in Nano Editor.

Advice from the nano editor:-
1. Ctrl + O (tender)
2. Enter
in 3. Ctrl + x (output)

Turn on the configurations we’ve made.

sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-acabled

sudo ln -s /etc/nginx/sites-available/MyBlog.conf /etc/nginx/sites-enabled/

1.6 Check configuration file

Every time you make changes to the Nginx configuration file, it is important to check for syntax errors. You can do this by executing the following command.

sudo nginx -t

If there are errors in your configuration file, the command output will indicate where exactly the error was found in the file.

Conversely, if none of your NGINX configuration files have syntax errors, you will get a result similar to the one below.

Inginx output : Configuration file /etc/nginx/nginx.conf Syntax in order
nginx : Configuration file /etc/nginx/nginx.conf Test successful

1.7 Rebooting the NGINXserver

If the test was successful, restart NGINX with the following command.

restart sudo service nginx

2. Cloning and start of the Express project

We’ve already created the Express backend and moved it to the GitHub repository. Clone the repository on our server.

Now, I’m cloning a simple express back end that I’ve already created.

The next assignment will clone this application on our server.

Guitar Clone https://github.com/techomoro/SimpleExpressBackend.git

Enter the project and define the dependencies using the following commands.

cd SimpleExpressBackend
npm i

Now start the Express application with pm2.

Start the pm2.js index

3. Buying a domain and modifying the DNS

Okay, our express background is ready. We can now link the domain name to access the REST API.

We can buy a domain from any domain registrar. Some of them are listed below.

This is where I choose Godaddy to buy the estate.

3.1 Searching for field

Log on to https://www.godaddy.com/ and search for the domain. If it is available, add it to the cart.

3.2 Selection of the options of package

Godaddy will let you buy your privacy, email address and domain hosting. I’d rather skip these package options here.

3.3 Completion of purchase

Complete the purchase by entering invoice and payment details. You can buy a domain for a period of 1 to 5 years. Here, I’ll buy it for a year.

3.4 Modification of DNS

Now select My products from the top menu. Here you can see the domain you bought.

Click DNS to display the DNS items.

Add an A listing with the api name and IP address of the server.

4. Configuration of SSL certificates with encryption capability

Configure the SSL certificate with the following command.

sudo certbot –nginx -d api.mynewblog33.com

Pay attention: Replace the domain name with your own name.

4.1 Implementation of automatic renewal forSSL certificates

Let’s encrypt the certificates for 90 days. But an order can update the certificate automatically.

Renew sudo certbot – test

4.2 Rebooting the NGINXserver

All settings will be displayed on our server after NGINX is restarted.

restart sudo service nginx

5. Access to the REST API

We now have access to the API we created using the URL below.

https://api.mynewblog33.com

Let’s take an example.

Summary

So we discussed the steps to follow to successfully implement the Express backend on the cloud server. We used a pre-built express on the Vultr VC2 server and connected the domain name.

Here we go:

Like the download…

You might like this.

deploy node js to production,nodejs express for production,node js express project setup,deploy express app to aws,host node js app free,deploy express app to heroku,node js api versioning,publish node api,how to deploy node js rest api,express api in docker,express cors docker,docker nodejs,azure cloud service node js,azure webapps express,deploy express app to azure app service,deploy node js to azure from github,node js simple project download,deploy strapi to azure,deploy to heroku express,how to create server on heroku,how to host express server on heroku,express server deployment,nodejs heroku express port,deploy react express app to heroku,create-react app azure pipelines,azure devops .net core react,how to deploy react web app on azure,deploy github react app to azure,deploy react app visual studio code,deploy react application on azure web app,nest js aws lambdas,@hewmen/serverless-plugin-typescript,nestjs microservice lambda,nestjs aws sam,nestjs serverless,nestjs graphql lambda,nodejs express serve html,npm http-server example,serve-index,express send file to client,node js static website,node file server,deploy express app netlify,deploy express app to server,express heroku port,deploy express app digitalocean,how to deploy nodejs api on heroku,vue-cli-service build,how to run vue project,deploy vue app to iis,vue-cli-service: not found,npm err! missing script: serve,vuejs prod,how to deploy node js application on linux server,deploy node.js app to server,how to deploy node js application on apache server,how to deploy node js application on windows server,deploy express app to local server,how to deploy node api on server

You May Also Like

🥇 Calculate the Cost of a Product in Excel  Step by Step Guide ▷ 2020

If you want to sell a product or offer a service to…

🥇 MICROSOFT POWERPOINT  What is it? + Alternatives ▷ 2020

One of the advantages of using Office software packages is that you…

Pytorch Image Augmentation using Transforms.

In-depth learning models generally require a lot of data for learning. In…

Fix: Google Photos not backing up on iPhone

For many iPhone users, Google Photos remains the first choice, even though…