The Node.js Task Management API is a RESTful API designed to handle task management with features like user authentication, multi-tenancy, and comprehensive data operations. Built with Node.js, Express, and MongoDB, this project provides a scalable and secure solution for managing tasks. It is containerized with Docker for consistent deployment across environments.
- User Authentication: Secure registration and login with JWT-based authentication.
- Task Management: Full CRUD (Create, Read, Update, Delete) operations for tasks.
- Multi-Tenancy: Support for multiple tenants with isolated data.
- Testing: Unit and integration tests ensure code reliability and correctness.
- Docker Integration: Simplifies deployment with Docker and Docker Compose.
- Logging and Validation: Robust logging and data validation for improved reliability.
- Node.js: JavaScript runtime for server-side development.
- Express: Web framework for building the API.
- MongoDB: NoSQL database for flexible data storage.
- Mongoose: ODM library for MongoDB.
- JWT: JSON Web Token for user authentication.
- Chai & Mocha: Testing frameworks for unit and integration tests.
- Docker: Containerization for consistent development and deployment.
Ensure the following are installed before setting up the project:
- Node.js: Version 18.x or higher.
- MongoDB: Either locally installed or running via Docker.
- Docker: (Optional) For containerized development and deployment.
Clone the repository to your local machine:
git clone https://github.com/munuhee/task-manager-api
cd your-repository
Install the project dependencies using npm:
npm install
Create a .env
file in the root directory with the following content:
NODE_ENV=development
MONGODB_URI=mongodb://localhost:27017/myDatabase
JWT_SECRET=your_jwt_secret
PORT=3000
- NODE_ENV: Set to
development
for local development orproduction
for production environments. - MONGO_URI: Connection string for MongoDB.
- JWT_SECRET: Secret key for signing JWT tokens.
- PORT: Port for the application server (default is
3000
).
To start the server, use:
npm start
The API will be accessible at http://localhost:3000
.
Use Docker to containerize the application:
docker-compose build
docker-compose up
The application will be available at http://localhost:3000
and MongoDB will be accessible at mongodb://localhost:27017
.
To stop and remove the containers:
docker-compose down
-
Register User:
POST /api/auth/register
- Request Body:
{ "username": "string", "password": "string", "email": "string" }
- Response:
{ "message": "User registered successfully" }
- Request Body:
-
Login User:
POST /api/auth/login
- Request Body:
{ "username": "string", "password": "string" }
- Response:
{ "token": "string" }
- Request Body:
-
Create Task:
POST /api/tasks
- Request Body:
{ "title": "string", "description": "string", "dueDate": "ISODate", "priority": "string" }
- Response:
{ "task": { "id": "string", "title": "string", ... } }
- Request Body:
-
Get Tasks:
GET /api/tasks
- Response:
[ { "id": "string", "title": "string", ... } ]
- Response:
-
Update Task:
PUT /api/tasks/:taskId
- Request Body:
{ "title": "string", "description": "string", "dueDate": "ISODate", "priority": "string" }
- Response:
{ "task": { "id": "string", "title": "string", ... } }
- Request Body:
-
Delete Task:
DELETE /api/tasks/:taskId
- Response:
{ "message": "Task deleted successfully" }
- Response:
Run unit tests to validate individual components:
npm test
Run tests:
npm test
- Application Port: The API runs on port 3000 by default.
- MongoDB Port: MongoDB runs on port 27017.
- Development Logging: Detailed logs are enabled.
- Production Logging: Reduced verbosity to optimize performance.
- Development: Detailed error messages and stack traces are enabled.
- Production: Generic error messages with detailed logs stored.