A RESTful API for managing tasks, built with Node.js, Express.js, and MongoDB.
- Features
- Prerequisites
- Installation
- Configuration
- Running the Server
- API Documentation
- Authentication
- Error Handling
- Testing
- Contributing
- User registration and authentication using JWT
- CRUD operations for tasks
- Associate tasks with authenticated users
- Input validation using Joi
- Error handling
- API documentation using Swagger
Before you begin, ensure you have met the following requirements:
- Node.js (v14.0.0 or later)
- npm (v6.0.0 or later)
- MongoDB (v4.0.0 or later)
Clone the repository:
git clone https://github.com/TheMarvelFan/TaskManager.git
cd TaskManagerInstall the dependencies:
npm install-
Create a
.envfile in the root directory of the project. -
Add the following environment variables to the
.envfile:
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret
PORT=3000Replace your_mongodb_connection_string with your actual MongoDB connection string and your_jwt_secret with a secure random string for JWT encryption.
To start the server in development mode with nodemon:
npm run devTo start the server in production mode:
npm startThe server will start running at http://localhost:3000 (or the port specified in your .env file).
The API documentation is available through Swagger UI. After starting the server, you can access the documentation at:
http://localhost:3000/api-docs
This interactive documentation provides detailed information about all available endpoints, request/response schemas, and allows you to test the API directly from the browser.
This API uses JWT (JSON Web Tokens) for authentication. To access protected routes, you need to include the JWT token in the Authorization header of your requests:
Authorization: Bearer YOUR_JWT_TOKENYou can obtain a JWT token by registering a new user or logging in with existing credentials.
The API uses a consistent error response format:
{
"message": "Error message describing what went wrong"
}Common HTTP status codes used:
- 200: Successful request
- 400: Bad request (e.g., invalid input)
- 401: Unauthorized (authentication required)
- 404: Resource not found
- 500: Internal server error
(Note: As of now, no automated tests have been implemented. This section can be updated once tests are added to the project.)
To run the test suite (when implemented):
npm testContributions to this project are welcome. Please follow these steps:
- Fork the repository
- Create a new branch:
git checkout -b feature-branch-name - Make your changes and commit them:
git commit -m 'Add some feature' - Push to the branch:
git push origin feature-branch-name - Create a pull request