Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task Management API

A Node.js-based Task Management API for managing tasks, with features like search, pagination, and authentication using JWT.


Features

  • 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.

Setup Instructions

1. Prerequisites

Make sure you have the following installed:

  • Node.js (v16 or later)
  • MongoDB (local or cloud-based, e.g., MongoDB Atlas)

2. Clone the Repository

git clone <repository-url>
cd <repository-folder>

3. Install Dependencies

npm install

4. Set Up Environment Variables

Create a .env file in the project root and configure the following:

PORT=5000
MONGO_URI=<your-mongodb-connection-string>
JWT_SECRET=<your-jwt-secret>

5. Run the Application

  • Start the server in development mode:
npm run dev
  • The server will run on http://localhost:5000 by default.

6. Testing the API

Use tools like Postman or cURL to test the endpoints.


Approach

Task Management Features

  • Task Schema: Defined in taskModel.js, with fields for title, description, status, createdAt, and updatedAt.
  • 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).

Authentication

  • JWT-Based: Used for secure access.
  • Middleware (authMiddleware.js) ensures routes are protected.
  • Users can register and log in to receive tokens.

Middleware

  • Logger: Logs incoming requests.
  • Error Handler: Catches and formats errors.

API Endpoints

Authentication

Method Endpoint Description
POST /api/auth/register Register a new user
POST /api/auth/login Log in as a user

Task Management

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

Dependencies

Backend

Dev Dependencies

  • Nodemon - Auto-restart during development

Future Improvements

  • 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.

Contact

For any issues or suggestions, feel free to open an issue in the repository or contact the project maintainer.

About

A backend API for managing tasks, built with Node.js, Express, and MongoDB. It includes features like task creation, search, pagination, and CRUD operations, along with JWT-based authentication and middleware for logging and error handling.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages