A Node.js-based Task Management API for managing tasks, with features like search, pagination, and authentication using JWT.
- Create, read, update, and delete tasks (CRUD operations).
- Search tasks by title and status.
- Pagination for task lists.
- JWT-based authentication for secure access.
- Middleware for logging and error handling.
Make sure you have the following installed:
- Node.js (v16 or later)
- MongoDB (local or cloud-based, e.g., MongoDB Atlas)
git clone <repository-url>
cd <repository-folder>npm installCreate a .env file in the project root and configure the following:
PORT=5000
MONGO_URI=<your-mongodb-connection-string>
JWT_SECRET=<your-jwt-secret>- Start the server in development mode:
npm run dev- The server will run on
http://localhost:5000by default.
Use tools like Postman or cURL to test the endpoints.
- Task Schema: Defined in
taskModel.js, with fields fortitle,description,status,createdAt, andupdatedAt. - Controllers: All task operations (create, read, update, delete) are handled in
taskController.js. - Search and Pagination: Implemented using query parameters (e.g.,
/api/tasks?title=example&status=Pending&page=1&limit=10).
- JWT-Based: Used for secure access.
- Middleware (
authMiddleware.js) ensures routes are protected. - Users can register and log in to receive tokens.
- Logger: Logs incoming requests.
- Error Handler: Catches and formats errors.
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register a new user |
| POST | /api/auth/login |
Log in as a user |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/tasks |
Get all tasks (search, paginate) |
| POST | /api/tasks |
Create a new task |
| GET | /api/tasks/:id |
Get a task by ID |
| PUT | /api/tasks/:id |
Update a task by ID |
| DELETE | /api/tasks/:id |
Delete a task by ID |
- Express - Web framework
- Mongoose - MongoDB ORM
- jsonwebtoken - JWT authentication
- dotenv - Environment variable management
- bcryptjs - Password hashing
- Nodemon - Auto-restart during development
- Add support for filtering tasks by creation or update date.
- Implement role-based access control (e.g., admin and user roles).
- Add unit and integration tests for the API endpoints.
For any issues or suggestions, feel free to open an issue in the repository or contact the project maintainer.