Deploy ReactJS and NodeJS App on Server with Jenkins
Published: 2021-01-14 12:50:26

Today in this article, we shall discuss how to build and deploy ReactJS and NodeJS applications on the server using Jenkins. More and more businesses these days are relying upon Jenkins because of the exclusive advantages that this famous continuous Integration tool brings.

  

For those who don’t know what Jenkin means, then allow us to enlighten you up on that first.

## What is Jenkins

It is an open-source automation tool crafted in Java via plugins made for continuous integration purposes. This tool is used for building and testing the software projects so that it becomes easy for the developers to accommodate the changes to the project, and making it simple for the users to collect a fresh build.

  

Using Jenkins helps in the continuous delivery of software by combining it with a wide range of testing and deployment technologies. We will cover ReactJS and NodeJS in this article.

  

## Advantages of Jenkins

Jenkins is a great tool because of the exclusive advantages that it serves. Let’s have a look at a few of them:

  

-   The tool is open-source and has an extensive development community.
    
-   It is easy to install and get started with Jenkins.
    
-   Jenkins has more than 1000 plugins to simplify your work. If you are not able to find a plugin to fulfill your need, then you can code and share the same with the community.
    
-   Jenkins is free of cost.
    
-   It is portable to other major platforms because of the fact that it is written in Java.
    

  

Now, you can check out the integration setup process.

  

## Let’s Deploy

We have provided a step-by-step guide here for an easy understanding of the concept. We shall build Node application, React application, and host it on Server.

  

STEP-1: Setup an Ubuntu server and render a static IP address

So first, we will host the application on Server. You will understand it better through this below-shared diagram:

  

![](https://lh3.googleusercontent.com/4yM-m8qcicX5ouxyvns5BFaR331MB0lW7PG_GVi_YVsOD_YDB6P-lQkrY8cqp7a87DL7wsPIHAIejtxIP2_BPhMX5eGQk8J2FIU8ZBZ0VL0ZQCPvke7tsVBrx7L0fKlw4po33FvH)

  

You will have to install a ubuntu server in the system. For this purpose, make an entry in, etc/Netplan/.yaml as shown below:

  

![](https://lh6.googleusercontent.com/upew-01NP7JOhSvFtMcwsRk_RMxZkoijCrNrDcGLEjiBzzQsvnusIJm-yqCCrt7uIBLcO215pAfu9ZsBFdFBkUmBv0lpIckXw_dVYJD2BtZ14-iXGwqtEsCx6S51CC-Rh7MWQV87)

  

Once you are done, then just save the file and apply the changes by executing the following command:

  

sudo netplan apply

  

After setting up the static IP, you will have to do the port forwarding so that we can access our application through public IP outside the local network.

  

STEP-2: Install Jenkins

  

We shall need the Java runtime environment to execute Jenkins. You can check for the same below:

  

sudo apt-get update

sudo apt-get install OpenJDK-8-JDK

java -version

  

![](https://lh6.googleusercontent.com/zbvB_PBpb1-dGPtB2eL0rCSxk7SHqYvV6kVO_LN7yLbnDUEAuriXG250EYXajpMTNUXhPJq5E5HFF2CBA7Clxt7926v4g3_n0bPxfIQAsOTGwwcmrI8JeQQImUfgB3-hL-niymst)

  

Once you are done with setting up the Java runtime environment, then you can install Jenkins as shown below:

  

wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -

  

sudo sh -c 'echo deb [http://pkg.jenkins-ci.org/debian](http://pkg.jenkins-ci.org/debian) binary/ > /etc/apt/sources.list.d/jenkins.list'

  

sudo apt-get install Jenkins

sudo systemctl start Jenkins

  

After the installation process is done, Jenkins shall launch automatically and we can visit the domain-name:8080 to access the same.

  

![](https://lh6.googleusercontent.com/ikORntdzkEAXXle1h1MxpyBTVUBS9YTsWUNLGche3mkqdFJf0RmjOcaH9okIr_hDN9Vc3oEUy6ZXGXdTjnOnZiBB-X21q2KscNKqwv45CNtUPJMbrtQCv702r9xnRXkxg-uTvxeV)

  

STEP-3: Install NodeJS on Ubuntu Server

  

We can start with installing the latest version of Node.js with Long-Term Support with the help of files in the [NodeSource package](https://github.com/nodesource/distributions).

  

First, you will have to install NodeSource PPA to access its content but ensure at the same time that it falls in your home directory, and use curl to collect the installation script for the Node.js 10.x files as shown below:

  

curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh

  

You will be able to verify the content of such script with nano or your favorite text editor as shown below:

  

nano nodesource_setup.sh

  

Once you are done with inspecting the script, then you can run it under sudo as follows:

  

sudo bash nodesource_setup.sh

  

The personal package archive shall be included in our configuration. The local package cache will also get automatically updated. After running the Nodesource configuration script, we will be able to install the Node.js package as follows

  

sudo apt install nodejs

  

If you want to check which version of Node.js has been installed after executing the initial steps, then simply type:

  

nodejs -v

  

![](https://lh6.googleusercontent.com/WTdw8wnmvnP0oulDfdgjcrgboQuryVTQp6hUUt6_V7o3mfar1W1pohiQ10lnGXRH2lneVc6FnzqddWKRQlRrQIH5ABu7AhThhGv9xesMKS4IKP90wXsgACkW6ie61qJrp8yrSVt8)

  

You should be able to observe that the package nodejs consist of the binary of nodejs, as well as npm, and a package manager for Node modules. Hence, there is no need to install npm separately.

  

The npm makes use of a configuration file in our home directory to record the status of the updates. It will be created the first time you run npm. You can simply run this command to check that npm has been installed and then create the configuration file as shown below:

  

![](https://lh3.googleusercontent.com/F7sfrbVTlxG39z0YA_xAvl5mnp2ZQLSwQc0Jz7IIjOXH0Q5hnuktJ3oqDUkDnqovdPL55RcB6bzwxs9nicTcvvBuJP9pOYdg6OA6WpLEKsyi6mvSdHrkdrqdYUwjM6fiUdmSObeL)

  

STEP-4: Install the PM2 Process Manager

  

Now at this step, we will have to install the PM2, which is a process manager for Node.js applications. With the help of PM2, it would become possible to force the apps to run as a daemon so that they can run in the background as a service.

  

You can use npm to install the latest version of PM2 on your server:

  

sudo npm install pm2@latest -g

  
  

STEP-5: Complete the GitHub configuration

  

We will be required to trigger a new build whenever a new push would be done to the repository and hence, it will become compulsory to configure Webhook in the first place.

  

We can set up the hook at the repository, so that whenever a push has been done the Github shall notify the same Jenkins server, sending a POST request. After that, you can click on settings and then Webhooks.

  

![](https://lh3.googleusercontent.com/_B55-0dD9S8leejUmysaYDEwmIvzn-rV0WeCPmCM3GbFvuGeMd5rkGxnQtSQsEIFphqnLhkh8ZzXDfFejPRvUPeatzKxLXKWRuwai6g9IDqktLOS0hDz0lCQfHN3CflQPQCIm0mu)

  

Now, we can add the Jenkins Webhook, but we will need the Jenkins Server IP, for configuring the same.

  
  

[http://192.168.1.4:8080/github-webhook/](http://192.168.1.4:8080/github-webhook/)

  

![](https://lh4.googleusercontent.com/ak9A2W1kirgaKv4h7BrKs05sc-ykM-uMQNywIyaR2cXg177s02Hf9qUdi3pqFulELbGxd3JSXsnMnah-jjT5WsepDDN4Q-0D4flekz0RE14Unjo7JyBpegeJXmMliGLmwdK54hwj)

  

Now simply hit Add and then save it. We are now almost done. But we still have to create the deployment job at Jenkins and test the same.

  

STEP-6: Creating a Jenkins freestyle job

  

Hit the New Item in the main menu because that would be the first step for creating Jenkins freestyle job. On the next page, you can enter an item name like GitHub Project_Back-end and select the Freestyle project.

  

Once you have clicked on OK, the configuration page shall appear, where you will have to set up:

  

General:

![](https://lh4.googleusercontent.com/ywASHAbhytObGGaEay4-KpVJ6AAXsbnCWugRmzbvlS2xovs2AuUT9zlHLJI_MHFLbmrb6bThjjG4pyrnyAoZV-WjrV5mEH33YdDJjt3x1jJDqvYgu42EjLVfACA3R7Q64B5fKBB2)

  
  

Source Code Management:

  

![](https://lh4.googleusercontent.com/sZudxd-5Rnh50gYQUCl1vFqdf8kjQozaaUwoyfuo38Ilpcma6EFl3HuFBruI_SMsxLhGDpUDpYHvYBHEbYPG7qoaPjZiOQoPS7ZMCdmmUuVKIzTmaMlWTbx2N2pA5Yg2F5ga9m4c)

  

If you have decided to construct a project from a private repository, then you will be required to add the credentials and then hit Add on the right. After that, select username as well as password. The username will be the username of GitHub and the password will be the GitHub password.

  

Triggers:

  

![](https://lh3.googleusercontent.com/uw984LCFMb0epygXj0laPrVrcGbaCiaZjh7I9nDO4g3_mQN-EJYKH9Kjnce7qsed_S5HkZxLtBg8UGGEljXJNvoQZrAkSxphESz_x9my9Xy4qB_w2bqH-zI_gBhEnekZDrymKBoA)

  

Build:

  

![](https://lh3.googleusercontent.com/wk7k5ThiY8yKl1A53LSrnYhNqWxhLKfr05DIDxTpzVJSdOB7RjW1cLUPUE98adkHar3Egde4fMY55k68jMhURNEojAW3qlN702j3Ifn_KYXzkn_hJaqjT3vzLJ-pDes860IVDMX1)

  

Now after reaching the final step, we will have to inform Jenkins to install the dependencies.

  

Final Output:

  

![](https://lh5.googleusercontent.com/WWb2o8_UkAZtNctrEJqmy74gKQiVccEgOv2Xh-oUxd0DYRn1rgDn-XfbIPJnKYCzS0n-iTjEc_yyZ3f0QWqmxIg_TREhCMLyTAf6S3zj5_r7j-8F619iIiGeaRTUiOfeUMAcV5Lv)

  
  
  
  

Conclusion

  

We have finally completed the deployment and we are all set up. With the Jenkins server and the application server up, every new push shall trigger a new deployment into our server. It is as easy as that. Once done, then you will be able to bag the merits of this amazing tool and see them in the action.