A simple full-stack task management system built with Node.js, Express, MongoDB, and JWT authentication.
This project demonstrates authentication, protected routes, role-based access control, and CRUD operations for tasks.
A basic frontend is included to interact with the backend APIs.
Backend
- Node.js
- Express.js
- MongoDB (Mongoose)
- JWT Authentication
- bcrypt (password hashing)
Frontend
- HTML
- CSS
- JavaScript (Fetch API)
Tools
- Postman (API testing)
- Git & GitHub
- User Registration
- User Login
- Password hashing using bcrypt
- JWT authentication
- Protected routes
- Role-based access control (Admin vs User)
- Create tasks
- View tasks
- Admin can view all tasks
- Basic frontend dashboard
- API documentation using Postman
backend-assignment │ ├── config │ └── db.js # MongoDB connection │ ├── middleware │ ├── authMiddleware.js # JWT verification │ └── roleMiddleware.js # Role based access (admin/user) │ ├── models │ ├── User.js # User schema │ └── Task.js # Task schema │ ├── routes │ ├── authRoutes.js # Register & Login APIs │ └── taskRoutes.js # Task APIs │ ├── frontend │ ├── register.html # User registration page │ ├── login.html # Login page │ ├── dashboard.html # Task dashboard │ └── style.css # Styling │ ├── server.js # Main server file ├── package.json # Dependencies ├── .env # Environment variables ├── postman_collection.json # API documentation ├── scalability.md # Scalability explanation └── README.md
POST /api/auth/register
Body
{
"name": "Anshya",
"email": "anshya@gmail.com",
"password": "123456"
}
Login
POST /api/auth/login
Body
{
"email": "anshya@gmail.com",
"password": "123456"
}
Response
{
"token": "JWT_TOKEN"
}
Task APIs
Create Task
POST /api/tasks
Headers
Authorization: Bearer TOKEN
Body
{
"title": "Finish Backend Assignment",
"description": "Create REST API with JWT"
}
Get User Tasks
GET /api/tasks
Headers
Authorization: Bearer TOKEN
Admin Get All Tasks
GET /api/tasks/admin/all
Headers
Authorization: Bearer TOKEN
Admin role required.
Setup Instructions
1 Install Dependencies
npm install
2 Create .env file
PORT=5000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_secret_key
3 Run Server
npm run dev
Server will start on
http://localhost:5000
Frontend Usage
Open the frontend files in a browser.
Start with
frontend/register.html
Flow:
Register → Login → Dashboard → Create Tasks
API Documentation
Postman collection is included.
Import file:
postman_collection.json
into Postman to test APIs.