A production-ready REST API that allows authenticated users to create and manage personal notes. The application implements authentication, ownership enforcement, and role-based access control.
This project was developed as part of a backend assignment to demonstrate API design, authentication, and database integration.
- JWT Authentication
- Secure password hashing using bcrypt
- Role-Based Access Control (RBAC)
- Notes CRUD operations
- Pagination and search support
- Refresh token mechanism
- Swagger API documentation
- Dockerized setup
- Node.js
- Express.js
- PostgreSQL
- JWT (JSON Web Tokens)
- Swagger (OpenAPI)
- Docker
src/
├── config/
│ db.js
│
├── middleware/
│ authMiddleware.js
│ roleMiddleware.js
│ errorMiddleware.js
│
├── routes/
│ authRoutes.js
│ noteRoutes.js
│
└── app.js
server.js
Dockerfile
README.md
.env.example
git clone https://github.com/BRshiva/notes-management-api.git
cd notes-management-api
npm install
Create a .env file in the root directory.
Copy values from .env.example.
Example:
PORT=5000
DATABASE_URL=postgresql://user:password@localhost:5432/notesdb
JWT_SECRET=your_secret
REFRESH_SECRET=your_refresh_secret
npm run dev
The server will run at:
http://localhost:5000
Swagger UI is available when the server is running.
Open the following URL in your browser:
http://localhost:5000/api-docs
You can test all API endpoints directly from Swagger.
| Method | Endpoint | Description |
|---|---|---|
| POST | /auth/register |
Register a new user |
| POST | /auth/login |
Login user and receive tokens |
| POST | /auth/refresh |
Generate new access token |
| Method | Endpoint | Description |
|---|---|---|
| GET | /notes |
Get notes for authenticated user |
| POST | /notes |
Create a new note |
| PUT | /notes/:id |
Update an existing note |
| DELETE | /notes/:id |
Delete a note |
- Can manage only their own notes
- Can view all notes
- Can delete any note
POST /auth/register
Request body:
{
"email": "test@example.com",
"password": "123456"
}
POST /auth/login
Request body:
{
"email": "test@example.com",
"password": "123456"
}
Response example:
{
"accessToken": "JWT_TOKEN",
"refreshToken": "REFRESH_TOKEN"
}
POST /notes
Headers:
Authorization: Bearer YOUR_ACCESS_TOKEN
Request body:
{
"title": "My First Note",
"content": "Example content"
}
Get paginated notes:
GET /notes?page=1&limit=10
Search notes by title:
GET /notes?search=meeting
Build Docker image:
docker build -t notes-api .
Run container:
docker run -p 5000:5000 notes-api
The application requires the following environment variables:
PORT
DATABASE_URL
JWT_SECRET
REFRESH_SECRET
Shiva Suman
Backend project demonstrating REST API design, authentication, and role-based access control.