A RESTful API for managing student tasks with JWT-based authentication. Built with Node.js, Express, and MongoDB.
π Live API: https://student-task-manager-api-latest.onrender.com
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB (Mongoose)
- Authentication: JWT (JSON Web Tokens)
- Node.js v18+
- MongoDB (local or Atlas)
# Clone the repository
git clone https://github.com/DeShyam01/student-task-manager-api.git
cd student-task-manager-api
# Install dependencies
npm installCreate a .env file in the root directory:
PORT=3000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key# Development
npm run dev
# Production
npm startServer will start at http://localhost:3000
https://student-task-manager-api-1.onrender.com
Note: All
/tasksroutes require a valid JWT token in theAuthorizationheader:Authorization: Bearer <your_token>
| Method | Endpoint | Auth | Description |
|---|---|---|---|
POST |
/api/v1/user/register |
β | Register a new user |
POST |
/api/v1/user/login |
β | Login and get JWT token |
GET |
/api/v1/user/profile |
β | Get logged-in user's profile |
// Request Body
{
"name": "Shyam",
"email": "shyam@example.com",
"password": "yourpassword"
}
// Response 201
{
"message": "User registered successfully",
"token": "<jwt_token>"
}// Request Body
{
"email": "shyam@example.com",
"password": "yourpassword"
}
// Response 200
{
"token": "<jwt_token>"
}// Response 200
{
"_id": "64abc...",
"name": "Shyam",
"email": "shyam@example.com",
"role": "student",
"createdAt": "2025-03-01T00:00:00.000Z",
"updatedAt": "2025-03-01T00:00:00.000Z"
}All task routes are protected β include the JWT token in every request.
| Method | Endpoint | Auth | Description |
|---|---|---|---|
GET |
/api/v1/tasks |
β | Get all tasks for logged-in user |
GET |
/api/v1/tasks/:id |
β | Get a specific task by ID |
POST |
/api/v1/tasks |
β | Create a new task |
PUT |
/api/v1/tasks/:id |
β | Update a task |
PATCH |
/api/v1/tasks/:id/complete |
β | Mark a task as complete |
DELETE |
/api/v1/tasks/:id |
β | Delete a task |
// Response 200
[
{
"_id": "64xyz...",
"title": "Complete DSA assignment",
"description": "Solve linked list problems",
"dueDate": "2025-03-10T00:00:00.000Z",
"priority": 1,
"status": "Pending",
"userId": "64abc...",
"createdAt": "2025-03-01T00:00:00.000Z",
"updatedAt": "2025-03-01T00:00:00.000Z"
}
]// Request Body
{
"title": "Complete DSA assignment",
"description": "Solve linked list problems",
"dueDate": "2025-03-10",
"priority": 1
}
// priority: 1 = High, 2 = Medium, 3 = Low
// Response 201
{
"_id": "64xyz...",
"title": "Complete DSA assignment",
"description": "Solve linked list problems",
"dueDate": "2025-03-10T00:00:00.000Z",
"priority": 1,
"status": "Pending",
"userId": "64abc...",
"createdAt": "2025-03-01T00:00:00.000Z",
"updatedAt": "2025-03-01T00:00:00.000Z"
}// Request Body (all fields optional)
{
"title": "Updated title",
"description": "Updated description",
"dueDate": "2025-03-15",
"priority": 2
}
// Response 200
{
"_id": "64xyz...",
"title": "Updated title",
"description": "Updated description",
"dueDate": "2025-03-15T00:00:00.000Z",
"priority": 2,
"status": "Pending",
"userId": "64abc...",
"createdAt": "2025-03-01T00:00:00.000Z",
"updatedAt": "2025-03-05T00:00:00.000Z"
}// Response 200
{
"_id": "64xyz...",
"title": "Complete DSA assignment",
"status": "completed",
"updatedAt": "2025-03-05T00:00:00.000Z"
}// Response 200
{
"message": "Task deleted successfully"
}student-task-manager-api/
βββ src/
β βββ controllers/
β β βββ taskController.js
β β βββ userController.js
β βββ middleware/
β β βββ authMiddleware.js
β βββ models/
β β βββ Tasks.js
β β βββ Users.js
β βββ routes/
β βββ taskRoutes.js
β βββ userRoutes.js
βββ server.js
βββ package.json
βββ .env
βββ .gitignore
| Field | Type | Required | Notes |
|---|---|---|---|
name |
String | β | |
email |
String | β | Unique |
password |
String | β | Stored hashed |
role |
String | β | "student" (default) or "admin" |
createdAt |
Date | β | Auto-set |
updatedAt |
Date | β | Auto-set |
| Field | Type | Required | Notes |
|---|---|---|---|
title |
String | β | |
description |
String | β | |
dueDate |
Date | β | |
priority |
Number | β | 1 = High, 2 = Medium, 3 = Low |
status |
String | β | "Pending" (default) or "completed" |
userId |
ObjectId | β | Ref to User β auto-set from JWT |
createdAt |
Date | β | Auto-set |
updatedAt |
Date | β | Auto-set |
- Register via
POST /api/v1/user/registerβ receive JWT token - Login via
POST /api/v1/user/loginβ receive JWT token - Include token in all protected requests:
Authorization: Bearer <token>