Your destination for complete Tech news

How to Create a REST API in Node.js with Express

599 0
< 1 min read

Intro:
Express.js is the most popular framework for building REST APIs in Node.js.

Snippet:

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

app.use(express.json());

app.get("/api/hello", (req, res) => {
  res.json({ message: "Hello World" });
});

app.listen(3000, () => console.log("Server running on http://localhost:3000"));

Takeaway:
Keep routes modular and use express.json() for parsing JSON requests.