What is Express JS & Setup

What is Express.js?

Express.js is a fast, minimal, and flexible web application framework built on Node.js. It helps you easily create web servers, APIs, and routes.


Why Use Express.js?

  1. Simple Routing
  2. Middleware Support
  3. Template Engines
  4. REST API Ready
  5. Lightweight and Fast
  6. Easy to Learn


How to Set Up Express.js

Create a New Project Folder

Express-2025


Initialize Node.js Project

npm init

Fill the details like:

  1. Package Name: node-js-2025
  2. Description: node js and express js tutorials in hindi 2025
  3. Entry Point: index.js (default)


Install Express

npm install express --save


Create Entry File – index.js

Basic Express Server

const express = require("express");

const app = express();

app.get("", (req, resp) => {
resp.send("<h1>Basic Node js example</h1>");
});

app.get("/about", (req, resp) => {
resp.send("<h1>This is about page</h1>");
});

app.get("/contact", (req, resp) => {
resp.send("<h1>This is contact page</h1>");
});

app.listen(3200);

Explanation:

  1. app.get() – Handles GET requests.
  2. resp.send() – Sends HTML or plain text response.
  3. app.listen(3200) – Server listens on port 3200.


Auto Restart with Nodemon

To avoid restarting the server manually every time:


Install Nodemon

npm i nodemon --save-dev


Then run your project using:

npx nodemon index.js

Now your server will auto-refresh on every file save.