๐Ÿ› ๏ธ Node.js

Build a REST API with Express.js โ€” Complete Beginner Tutorial

๐Ÿ“… Jun 14, 2026 โฑ 6 min read

Every app needs an API. Express makes Node servers pleasant โ€” here is a complete CRUD API you can run right now.

Setup

mkdir api && cd api
npm init -y
npm install express

The whole API

const express = require("express");
const app = express();
app.use(express.json());          // parse JSON bodies

let students = [{ id: 1, name: "Priya", cgpa: 8.9 }];

app.get("/api/students", (req, res) => res.json(students));

app.get("/api/students/:id", (req, res) => {
  const s = students.find(x => x.id === +req.params.id);
  s ? res.json(s) : res.status(404).json({ error: "Not found" });
});

app.post("/api/students", (req, res) => {
  const s = { id: Date.now(), ...req.body };
  students.push(s);
  res.status(201).json(s);
});

app.put("/api/students/:id", (req, res) => { /* find + update */ });
app.delete("/api/students/:id", (req, res) => {
  students = students.filter(x => x.id !== +req.params.id);
  res.status(204).end();
});

app.listen(3000, () => console.log("API on :3000"));

REST conventions that interviews check

Test with Postman or curl, then deploy free on Render โ€” see the hosting guide.

โ† All Articles