A minimal Node.js + Express REST API boilerplate that reads from a local JSON file and includes Swagger UI documentation generated with swagger-autogen and served with swagger-ui-express.
- Minimal Node Express REST API
- Reads from a simple
.jsonfile (no database required) - Integrated Swagger UI setup using:
- Works with Node.js 18+ and Node.js 22+ (ESM imports)
- Node.js
- Express 5
- CORS
- Swagger UI Express
- Swagger Autogen
Click the “Use this template” button at the top of the repo or clone it manually:
git clone https://github.com/ypdev19/node-express-basic-api-json-swagger-boilerplate.git
cd node-express-basic-api-json-swagger-boilerplatenpm installnpm run swagger-autogennpm start- The server will start at
http://localhost:8080 - Swagger UI available at
http://localhost:8080/api-docs
Depending on your Node.js version, you may need to import swagger-output.json differently:
You can directly import JSON using the assert syntax:
import swaggerFile from "./swagger-output.json" assert { type: "json" };Use createRequire instead:
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const swaggerFile = require("./swagger-output.json");| Method | Path | Description |
|---|---|---|
| GET | /api/articles | Get list of articles from JSON |
| GET | /api-docs | Swagger UI documentation |
- Extend the project by adding new endpoints under
src/routes/. - The "business" logic is under
src/service/. - Update
swagger.jsto include new routes. - Store additional datasets under
data/. - Re-run
npm run swagger-autogeneach time you modify endpoints.
- This is a lightweight boilerplate meant for quick REST API prototypes.
- No database is required, it reads directly from local JSON.
Checkout the step by step tutorial 👉 Add Swagger UI to Nodejs Express REST API: Simple Setup Guide
MIT License © Yuli Petrilli