February 1, 2025
Building REST APIs with Express
Express.js is a minimal and flexible Node.js web application framework that provides a robust set of features for building web and API applications.
Setting Up
npm install express
Core Concepts
- Routing: Define endpoints with
app.get(),app.post(), etc. - Middleware: Functions that execute during the request-response cycle.
- Error Handling: Centralized error handling middleware keeps code clean.
Example
import express from "express";
const app = express();
app.get("/api/health", (req, res) => {
res.json({ status: "ok" });
});
app.listen(3000);