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?
- Simple Routing
- Middleware Support
- Template Engines
- REST API Ready
- Lightweight and Fast
- 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:
- Package Name:
node-js-2025
- Description:
node js and express js tutorials in hindi 2025
- 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:
app.get()
– Handles GET requests.resp.send()
– Sends HTML or plain text response.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.