A simple and efficient task manager application built with Node.js, Express, and MongoDB. This full-stack application allows users to create, read, update, and delete tasks with a clean web interface.
- ✅ Create new tasks
- 📋 View all tasks
- ✏️ Edit existing tasks
- 🗑️ Delete tasks
- ✔️ Mark tasks as completed/incomplete
- 🎨 Clean and responsive UI
- 🔄 RESTful API architecture
Backend:
- Node.js
- Express.js v5.2.1
- MongoDB with Mongoose v9.1.6
- CORS enabled
Frontend:
- Vanilla JavaScript
- HTML5/CSS3
- Font Awesome icons
Before running this application, make sure you have:
- Node.js (v14 or higher)
- MongoDB (local installation or MongoDB Atlas account)
- npm or yarn package manager
- Clone the repository:
git clone <repository-url>
cd task-manager- Install dependencies:
npm install- Create a
.envfile in the root directory:
PORT=3000
HOSTNAME=localhost
DB_URL=mongodb://localhost:27017/task-managerFor MongoDB Atlas, use:
DB_URL=mongodb+srv://<username>:<password>@cluster.mongodb.net/task-managerRun with auto-reload using nodemon:
npm run devnpm startThe server will start at http://localhost:3000
http://localhost:3000/api/v1/tasks
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/tasks |
Get all tasks |
| GET | /api/v1/tasks/:id |
Get a single task by ID |
| POST | /api/v1/tasks |
Create a new task |
| PATCH | /api/v1/tasks/:id |
Update a task |
| DELETE | /api/v1/tasks/:id |
Delete a task |
POST /api/v1/tasks
Content-Type: application/json
{
"name": "Complete project documentation",
"description": "Write comprehensive docs for the task manager",
"status": "pending",
"priority": "high",
"category": "work",
"dueDate": "2026-03-15"
}Response:
{
"message": "Created",
"data": {
"_id": "507f1f77bcf86cd799439011",
"name": "Complete project documentation",
"description": "Write comprehensive docs for the task manager",
"status": "pending",
"priority": "high",
"category": "work",
"dueDate": "2026-03-15T00:00:00.000Z",
"createdAt": "2026-03-05T10:30:45.123Z",
"updatedAt": "2026-03-05T10:30:45.123Z"
}
}GET /api/v1/tasks?page=1&limit=10&status=pending&priority=high&category=work&sort=-dueDateResponse:
{
"data": {
"tasks": [
{
"_id": "507f1f77bcf86cd799439011",
"name": "Complete project documentation",
"description": "Write comprehensive docs for the task manager",
"status": "pending",
"priority": "high",
"category": "work",
"dueDate": "2026-03-15T00:00:00.000Z",
"createdAt": "2026-03-05T10:30:45.123Z",
"updatedAt": "2026-03-05T10:30:45.123Z"
}
],
"totalTasks": 5,
"currentPage": 1,
"totalPages": 1
}
}Query Parameters:
page(number) - Page number for pagination (default: 1)limit(number) - Number of tasks per page (default: 10)status(string) - Filter by status:pending,doing,completedpriority(string) - Filter by priority:low,medium,highcategory(string) - Filter by categorysearch(string) - Search tasks by name (case-insensitive)sort(string) - Sort field (prefix with-for descending, e.g.,-dueDate)
GET /api/v1/tasks/507f1f77bcf86cd799439011Response:
{
"task": {
"_id": "507f1f77bcf86cd799439011",
"name": "Complete project documentation",
"description": "Write comprehensive docs for the task manager",
"status": "pending",
"priority": "high",
"category": "work",
"dueDate": "2026-03-15T00:00:00.000Z",
"createdAt": "2026-03-05T10:30:45.123Z",
"updatedAt": "2026-03-05T10:30:45.123Z"
}
}PATCH /api/v1/tasks/507f1f77bcf86cd799439011
Content-Type: application/json
{
"status": "doing",
"priority": "medium"
}Response:
{
"message": "Task updated successfully",
"updatedTask": {
"_id": "507f1f77bcf86cd799439011",
"name": "Complete project documentation",
"description": "Write comprehensive docs for the task manager",
"status": "doing",
"priority": "medium",
"category": "work",
"dueDate": "2026-03-15T00:00:00.000Z",
"createdAt": "2026-03-05T10:30:45.123Z",
"updatedAt": "2026-03-05T10:30:50.456Z"
}
}DELETE /api/v1/tasks/507f1f77bcf86cd799439011Response:
{
"message": "Deleted",
"deletedTask": {
"_id": "507f1f77bcf86cd799439011",
"name": "Complete project documentation",
"description": "Write comprehensive docs for the task manager",
"status": "doing",
"priority": "medium",
"category": "work",
"dueDate": "2026-03-15T00:00:00.000Z",
"createdAt": "2026-03-05T10:30:45.123Z",
"updatedAt": "2026-03-05T10:30:50.456Z"
}
}01-task-manager/
├── controllers/
│ └── tasks.js # Business logic for task operations
├── database/
│ └── connectDB.js # MongoDB connection setup
├── models/
│ └── Tasks.js # Mongoose schema and model
├── public/
│ ├── browser-app.js # Frontend JavaScript
│ ├── edit-task.js # Edit task functionality
│ ├── main.css # Custom styles
│ ├── normalize.css # CSS reset
│ └── task.html # Task edit page
├── routes/
│ └── tasks.js # API route definitions
├── utils/
│ └── helpers.js # Utility functions for filtering
├── .env # Environment variables (not in repo)
├── .gitignore
├── app.js # Main application entry point
├── index.html # Main page
├── package.json
└── README.md
{
name: {
type: String,
required: true,
maxLength: 25
},
description: {
type: String,
trim: true
},
status: {
type: String,
enum: ['pending', 'doing', 'completed'],
required: true,
default: 'pending',
lowercase: true
},
priority: {
type: String,
enum: ['low', 'medium', 'high'],
required: true,
lowercase: true
},
category: {
type: String,
enum: ['personal', 'work', 'finance', 'study', 'health', 'chore', 'family', 'sports', 'others'],
required: true,
lowercase: true
},
dueDate: {
type: Date,
validate: {
validator: (date) => date >= new Date().setHours(0, 0, 0, 0),
message: 'Due date must be in the future'
}
},
createdAt: {
type: Date,
default: Date.now
},
updatedAt: {
type: Date,
default: Date.now
}
}| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 3000 |
HOSTNAME |
Server hostname | localhost |
DB_URL |
MongoDB connection string | Required |
The API returns appropriate HTTP status codes:
200- Success (GET, PATCH, DELETE)201- Created (POST)500- Internal Server Error
Error responses include a message and optional error details (in development mode):
{
"message": "Internal Server Error",
"error": {
"message": "Tasks.find is not a function",
"name": "TypeError"
}
}Note: In production, detailed error information is not exposed to clients for security reasons. Check server logs for debugging.