Express is a minimal web framework for Node.js, widely used to build REST APIs and backend services in JavaScript.

What is Express?

Express provides routing, middleware support and request/response helpers on top of Node's built-in HTTP module.

Project Setup

bash
npm init -y
npm install express

Defining Routes

javascript
const express = require("express");
const app = express();

app.get("/", (req, res) => {
  res.send("Hello, DevQura!");
});

app.listen(3000, () => console.log("Server running on port 3000"));

Middleware

Middleware functions run between the incoming request and your route handler — useful for logging, authentication and parsing request bodies.

javascript
app.use(express.json()); // parse JSON request bodies

app.use((req, res, next) => {
  console.log(`${req.method} ${req.url}`);
  next();
});

Working with JSON

javascript
app.post("/users", (req, res) => {
  const { name } = req.body;
  res.status(201).json({ created: name });
});
Node.jsExpressBackendAPI