This is a simple Task Manager API built using Node.js, Express.js, and MongoDB. It supports user registration and authentication using JWT and allows users to perform full CRUD operations on tasks. Each task is associated with a specific authenticated user.
- User Registration and Login (JWT Authentication)
- Create, Read, Update, and Delete (CRUD) tasks
- Tasks are user-specific
- RESTful API architecture
- MongoDB for data storage
Node.jsExpress.jsMongoDBJSON Web Token (JWT)Bcrypt.js(for password hashing)Postman(for testing)
Task_Manager_API/
├── controllers/
│ ├── taskController.js
│ └── userController.js
├── middleware/
│ └── auth.js
├── models/
│ ├── Task.js
│ └── User.js
├── routes/
│ ├── taskRoutes.js
│ └── userRoutes.js
├── .env
├── app.js
├── server.js
- Clone the repository
git clone https://github.com/saarv3sh7/Task-Manager-API.git
cd Task_Manager_API
- Install dependencies
npm install
- Create
.envfile
PORT=5000
MONGO_URI=mongodb://127.0.0.1:27017/task-manager-api
JWT_SECRET=your_jwt_secret
- Start MongoDB locally
mongod --dbpath <MongoDB-db-Folder>
- Run the server
npm start
Server runs on: http://localhost:5000
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/users/register | Register new user |
| POST | /api/users/login | Login and get JWT |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/tasks | Get all user tasks |
| POST | /api/tasks | Create new task |
| PUT | /api/tasks/:id | Update task by ID |
| DELETE | /api/tasks/:id | Delete task by ID |
- Register
- Method:
POST - URL:
http://localhost:5000/api/users/register - Body (raw JSON):
{ "name": "Sarvesh", "email": "test@example.com", "password": "123456" }
- Login
- Method:
POST - URL:
http://localhost:5000/api/users/login - Body (raw JSON):
{ "email": "test@example.com", "password": "123456" } - Copy the
tokenfrom response for the next requests
- Get All Tasks
- Method:
GET - URL:
http://localhost:5000/api/tasks - Header:
Authorization: Bearer <token>
- Create Task
- Method:
POST - URL:
http://localhost:5000/api/tasks - Header:
Authorization: Bearer <token> - Body:
{ "title": "Complete Assignment", "description": "Finish backend API assignment" }
- Update Task
- Method:
PUT - URL:
http://localhost:5000/api/tasks/<task_id> - Header:
Authorization: Bearer <token> - Body:
{ "completed": true }
- Delete Task
- Method:
DELETE - URL:
http://localhost:5000/api/tasks/<task_id> - Header:
Authorization: Bearer <token>