NodeJs

How to build a server using NodeJs with Express?

Rohan Ravindra Kadam
3 min readSep 13, 2022

Hello 👋 It's Rohan Ravindra Kadam😎,

In this blog, we will build a server using NodeJs with Express. Before directly jumping into the development of the server we will need to cover some prerequisites. Let’s jump into some of the requirements.

How to Build A server using NodeJs with Express? Rohan Ravindra Kadam

⚡Prerequisites

📌 What is Server?

A server is a computer program or device that provides a service to another computer program and its user, also known as the client.

📌 What’s NodeJs?

As an asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications. In the following “hello world” example, many connections can be handled concurrently. Upon each connection, the callback is fired, but if there is no work to be done, Node.js will sleep.

📌 What’s Express?

The fast, unopinionated, minimalist web framework for node.

Now lets us jump into building a server using Nodejs with Express

⚡Development Phase

📌Step 1: Let's Create a Project directory

This project directory will eventually include both the server-side and the client-side code.

mkdir server-app

📌Step 2: Let’s Create a Project directory

The below command helps creates a package.json file in the root directory. This file keeps track of our app scripts and manages any dependencies our server needs and many more.

npm init -y

package.json file text

package.json

📌Step 3: Adding dependencies Express

For our server, we need to install the following dependencies.

npm i express

Inside package.json file , we would find installed dependencies

package.json

📌Step 4: Let us Create an express Server

  1. Importing Express into Server.js file.
const express = require('express');

2. Assigning app and port into Server.js file

const app = express();const port = 3000;

3. Final Code Snapshot

server.js

⚡Conclusion:-

In the article, we build a server using express in NodeJs. Node.js is emerging as a universal platform used for web applications, IoT, mobile, enterprise application development, and microservice architectures.

Please do share and clap 👏 if you find the article useful. Follow me on medium Rohan Ravindra Kadam and on Twitter at rohankadam25

Thank You, Viewers — Rohan Kadam

--

--