A simple RESTful API built with NestJS for managing users.
This project demonstrates clean architecture, DTO validation, and CRUD operations following best practices.
- NestJS — Node.js framework
- TypeScript — Strongly typed JavaScript
- Jest — Testing framework
The main project structure is as follows:
src/
├── app.module.ts
├── config
│ └── config.ts
├── database/
│ └── mock-users.json
├── main.ts
└── modules/
└── users/
├── dto/
│ ├── create-users.dto.ts
│ ├── get-users.dto.ts
│ └── update-users.dto.ts
├── enum/
│ └── role.enum.ts
├── users.controller.ts
├── users.module.ts
├── users.repository.ts
└── users.service.ts
git clone https://github.com/RJHXA/rest-api.git
cd rest-apiPrerequisite: Node.js and npm must be installed on your machine.
npm installCopy the .env.example file to .env and adjust if needed:
cp .env.example .env-
PORT: The port on which the project will run (recommended: 3000, since all examples use this port)
-
NODE_ENV: The environment for the application (development, test, production, etc.)
-
USERS_FILE: Path to the mock users JSON file
Example .env file used in the project:
USERS_FILE=src/database/mock-users.json
PORT=3000
NODE_ENV=developmentnpm run startTo ensure the tests do not overwrite the mock users you created, a separate mock users dataset is used exclusively for testing purposes.
To run the end-to-end tests for the User Module:
npm run test:e2eFor a better experience, you can explore and test all endpoints using the Swagger UI (available while the application is running) at:
👉 http://localhost:3000/api/docs
curl -X POST http://localhost:3000/users \
-H "Content-Type: application/json" \
-d '{"name": "John Doe", "email": "john@example.com", "role": "admin", "isActive": true}'
curl http://localhost:3000/users
Change :id for a valid number on user mock
curl http://localhost:3000/users/:id
Change :id for a valid number on user mock
curl -X PATCH http://localhost:3000/users/:id \
-H "Content-Type: application/json" \
-d '{"name": "Jane Doe"}'
Change :id for a valid number on user mock
curl -X DELETE http://localhost:3000/users/:id
