Continuous Integration & Continuous Deployment Tutor. NodeJs + Jenkins+ GitLab, Series #1.

Ajay Sharvesh M P
4 min readJan 30, 2020

Welcome Folks!

Hey Buddies, Welcome to CI/CD Tutor of Series #1, In this following series of tutors, I’ll be covering the DevOps stuff called Continuous Integration and Continuous Deployment of your NodeJs Application. In this tutor, I’ll be covering only, how to create a NodeJs App and the following series of tutors, let’s see step by step process of CI/CD into Jenkins. Let’s Walkthrough on NodeJs.

What is NodeJs?

NodeJs used to build for the backend of your application. It’s used to create and handle API (Application Programming Interface). API is nothing but a communication protocol for different programs to simplify the implementation of your software.

  1. NodeJs is an Open Source Server Environment
  2. NodeJs uses Javascript on the server
  3. NodeJs is independent to the many operating systems (Windows, Mac, Linux, etc.,.).

What can we do with NodeJs?

  1. It can create, delete, read, write, open and close the files on the server.
  2. It can add, delete and modify the data in the database.
  3. NodeJs runs single-threaded, non-blocking, asynchronous programming, which is very memory efficient for your application.

Let’s jump into practical session of creating a NodeJs App..!

Create Your First NodeJs App

Step #1: Download & Install NodeJs.

Go to NodeJs.Org, and download the latest or stable NodeJs Version and Install it. I always recommend you to use the stable version of NodeJs.

To check whether the NodeJs install successfully or not and to check the version, follow the command in terminal/command prompt.

node -v

It prints the version number like this,

v10.16.3

Step #2: Download and Install VS Code

Visual Studio Code is the lightweight IDE, you can work on NodeJs in this IDE. If you don’t have VS Code, download here.

Step #3: Open VS Code and Start creating the app.

Create the folder and name it as you wish and open up the terminal/command prompt in that folder and use this command to open the VS Code.

code .

VS Code will open, and create the mentioned files,

Create index.js and package.json file. And copy-paste the following code.

In package.json, use this code,

{
“name”: “sample-nodejs-app”,
“description”: “This sample app is to test deploy in jenkins”,
“version”: “0.0.1”,
“private”: true,
“dependencies”: {
“express”: “4.17.1”
},
“devDependencies”: {
“mocha”: “7.0.1”,
“supertest”: “4.0.2”
}
}

The package.json file is used to maintain the dependency version in your application.

Express is the Node Framework, used to listen to the server.

Mocha is the testing framework for Node.

Supertest is for high-level abstraction for HTTP Testing.

Now, we defined the dependencies in the package.json file. Now we have to install them, to install follow this command,

npm install

NPM is Node Package Manager, which is used to puts modules in place so that node can find them, and manages dependency conflicts intelligently. It is extremely configurable to support a wide variety of use cases. Most commonly, it is used to publish, discover, install, and develop node programs.

After executing the above command, you can see the folder in your app called node_modules. That maintains all your dependencies.

Now let’s start writing code in index.js file, copy-paste the following code.

//This imports the node framework -> express
var express = require(‘express’);

var app = express();
/* This responds with "hello world" message for requests that hit our "localhost:3000/" -> this url is root */
app.get(‘/’, function (request, response) {
response.send(‘Hello world!’);
});
//Server listen to port 3000 by default
app.listen(process.env.PORT || 3000);

module.exports = app;

After adding these lines of code in index.js, run this command in the terminal/command prompt.

node index.js

Now copy this URL and paste it into any of the browsers to see the response from the server.

localhost:3000

If you see ‘hello world’ message in the browser, then you’re ready to go.

Message from Node Server

Voila..!

Done with creating a sample NodeJs app, and in the next series, we will add this project to GitLab using few git commands. And let’s meet in the next series, buh-bye guys. Love from Sharvesh.

--

--