This project is a secure and scalable RESTful API built with Node.js, Express and MongoDB. It includes CRUD operations, JWT based authentication and built with clean architecture principles with separate layers for routes, controllers, models and middlewares which ensures maintainability.
The user password is secured by hashing before saving to the database, token expiration is included for security, input validation to check for clean input and error handling with appropriate messages and status code for developers.
This project is fully tested on Postman by checking all the routes for errors and success messages. It also production ready which can be easily deployed to cloud platforms.
A RESTful API for managing user data with JWT-based authentication. This API provides endpoints for user registration, authentication, and CRUD operations on user records.
http://localhost:4000
This project uses JWT based authentication system which includes token in the authorization header for protected endpoints.
Authorization: Bearer <jwt-token>
{
"status": "success",
"message": "success message",
date: {...}
}
{
"status": "error",
"message": "error message"
}
-
POST:
/auth/users
Request Body:
{ "name": "Kishan", "email": "kishan@mail.com", "password": "kishan123", "phone": "1234567" }
Success Response:
{ "status":"success", "message":"User created successfully!" }
Error Response:
{ "status":"error", "message":"User already exists!" }
-
POST
/auth/login
Request Body:
{ "email": "kishan@mail.com", "password": "kishan123" }
Success Response:
{ "status": "success", "message": "User Logged in successfully!", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." }
Error Response:
{ "status":"error", "message":"Invalid credentials!" }
-
GET
/users
Authorization: Bearer <jwt-token>
Success Response:
{ "status":"success", "data": [ { "id":"6895aac93f14fcfbd822e70d", "name":"Kishan", "email":"kishan@mail.com", "phone":"1234567" }, ... ] }
-
GET
/users/:id
Authorization: Bearer <jwt-token>
Success Response:
{ "status": "success", "data": { "id": "6894568fb24b2ef6aae32ed9", "name": "Kishan", "email": "kishan@mail.com", "phone": "1234567" } }
Error Response:
{ "status":"error", "message":"User not found!" }
-
PUT
/users/:id
Authorization: Bearer <jwt-token>
Request Body:
{ "name": "Krish", "email": "krish@mail.com", "password": "krish123", "phone": "999999" }
Success Response:
{ "name": "Krish", "email": "krish@mail.com", "password": "krish123", "phone": "999999" }
Error Response:
{ "status":"error", "message":"User not found!" }
-
DELETE
/users/:id
Authorization: Bearer <jwt-token>
Success Response:
{ "status": "success", "message": "User deleted successfully!" }
Error Response:
{ "status":"error", "message":"User not found!" }
-
npm install
-
npm run dev