A RESTful API for managing user authentication and todo notes, built with Node.js, TypeScript, MongoDB, and Redis using Hexagonal Architecture.
- Node.js >= 18
- MongoDB instance (local or cloud)
- Redis instance (local or cloud)
npm installCreate a .env file in the root directory and set the following:
PORT=3000
MONGO_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/dbname
JWT_SECRET=your_jwt_secret
REDIS_HOST=your_redis_host
REDIS_PORT=your_redis_port
REDIS_PASSWORD=your_redis_passwordnpm run devServer will start at http://localhost:PORT
| Method | Endpoint | Description | Request Body | Response Example |
|---|---|---|---|---|
| POST | /api/v1/auth/register |
Register new user | { "email": "user@example.com", "password": "secret123" } |
{ "token": "jwt_token_here" } |
| POST | /api/v1/auth/login |
Login existing user | { "email": "user@example.com", "password": "secret123" } |
{ "token": "jwt_token_here" } |
All /note routes require a Bearer token in the Authorization header.
| Method | Endpoint | Description | Request Body | Response Example |
|---|---|---|---|---|
| POST | /api/v1/note/create |
Create a new note | { "text": "Buy groceries" } |
{ "note": { "_id": "123", "text": "Buy groceries", "isDone": false, "userId": "123" } } |
| PUT | /api/v1/note/update |
Update a note | { "noteId": "123", "text": "Buy groceries", "isDone": true } |
{ "note": { "_id": "123", "text": "Buy groceries", "isDone": true, "userId": "123" } } |
| DELETE | /api/v1/note/delete |
Delete a note | { "noteId": "123" } |
{ "note": { "_id": "123", "text": "Buy groceries", "isDone": false, "userId": "123" } } |
| GET | /api/v1/note/list |
List notes by user | None (uses token for user ID) | { "notes": [ { "_id": "123", "text": "Buy groceries", "isDone": false, "userId": "123" } ] } |
npm run testMIT