A simple API in Node.js + Express with dynamic route loading and automatic documentation via Swagger.
- Express server with JSON support
- Automatic route loading from the api/routes folder
- Swagger documentation available in /docs
- Ready-to-use endpoint example
- api/index.ts: application entry point
- api/config/routerLoader.ts: dynamic route loading and Swagger
- api/routes/: organization of routes by module
- Node.js 18+
- pnpm / npm
pnpm install
npm installCreate a .env file based on .env.example:
API_PORT=3000pnpm api
npm run apiThe API will be available at:
curl -X POST http://localhost:3000/api/example/add \
-H "Content-Type: application/json" \
-d '{"name":"Maria","adresse":"Lisboa"}'- The server disables the x-powered-by header
- The body is limited to 100kb
- Basic input validation has been added to the example endpoint
- Avoid exposing secrets in the repository and keep the .env file out of version control
- Add authentication and authorization
- Insert more robust validation with zod or joi
- Add automated tests
- Better separate business logic from handlers