A simple NestJS application that provides CRUD APIs for managing persons with in-memory storage.
- Create Person: Add a new person with name, gender, and date of birth
- Get Person by ID: Retrieve a specific person by their unique ID
- Get All Persons: Retrieve all persons in the system
- Delete Person by ID: Remove a person from the system
Each person has the following properties:
id: Number (1-1000, auto-generated sequentially)name: String (required)gender: String (required, must be 'male', 'female', or 'other')dateOfBorn: Number (required, birth year between 1900 and current year)
- Install dependencies:
npm install- Start the application:
npm run start:devThe application will run on http://localhost:3000
Note: The start:dev command automatically kills any process running on port 3000 before starting to prevent "port already in use" errors.
- Method:
POST - URL:
/persons - Body:
{
"name": "John Doe",
"gender": "male",
"dateOfBorn": 1990
}- Response: Returns the created person with generated numeric ID (1-1000)
- Method:
GET - URL:
/persons - Response: Returns array of all persons
- Method:
GET - URL:
/persons/:id - Response: Returns the person with specified ID
- Method:
PUT - URL:
/persons/:id - Body: (All fields are optional)
{
"name": "Jane Doe",
"gender": "female",
"dateOfBorn": 1992
}- Response: Returns the updated person
- Method:
DELETE - URL:
/persons/:id - Response: 204 No Content
curl -X POST http://localhost:3000/persons \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"gender": "male",
"dateOfBorn": 1990
}'curl http://localhost:3000/personscurl http://localhost:3000/persons/1curl -X PUT http://localhost:3000/persons/1 \
-H "Content-Type: application/json" \
-d '{
"name": "John Smith",
"dateOfBorn": 1991
}'curl -X DELETE http://localhost:3000/persons/1This application uses persistent file storage with the following features:
- Data is automatically saved to
data/persons.jsonafter every create, update, or delete operation - Data is automatically loaded from the file when the application starts
- Data persists between application restarts - no data loss!
- No database setup is required - uses simple JSON file storage
- The
data/directory is created automatically if it doesn't exist
- File Path:
data/persons.json(in the project root) - Format: Pretty-printed JSON with proper Date object handling
- Auto-backup: Data is saved immediately after every operation
npm run start: Start the applicationnpm run start:dev: Start in development mode with auto-reloadnpm run start:debug: Start in debug modenpm run build: Build the applicationnpm run test: Run testsnpm run lint: Run linter
- NestJS (Node.js framework)
- TypeScript
- Class-validator (Input validation)
- UUID (Unique ID generation)
- Express (HTTP server)