This repository contains the backend code for a Task Manager application built with JavaScript, Node.js, and MongoDB. This README provides an overview of the project, instructions for setup and configuration, and guidance on using the API.
The Task Manager backend is the server-side component of a task management application. It provides RESTful API endpoints for managing tasks and user accounts. The backend is built using Node.js, Express.js, and MongoDB, and it includes authentication features for user registration and login.
- User authentication using JWT (JSON Web Tokens).
- Create, read, update, and delete tasks.
- Create and manage user accounts.
- Secure API endpoints with authentication middleware.
- Error handling and validation.
- Email sending.
- Unit testing using jest and supertest.
Before you begin, ensure you have met the following requirements:
- Node.js and npm installed.
- MongoDB server running (locally or on a remote server).
- A code editor (e.g., Visual Studio Code).
To install and set up the project, follow these steps:
- Clone the repository to your local machine:
git clone https://github.com/your-username/task-manager-backend.git
- Navigate to the project directory:
cd task-manager-backend
- Install the required dependencies:
npm install
Before running the application, you need to configure the environment variables. Create a new directory named config in the root of the project and create a .env file and add the following variables:
PORT=3000
NODEMAILER_KEY=your-nodemailer-api-key
JWT_SECRET=your-jwt-secret-key
MONGOOSE_URL=your-mongodb-connection-url
PORT
: The port on which the server will run.MONGODB_URL
: The connection URL for your MongoDB database.JWT_SECRET
: A secret key for JWT token generation.NODEMAILER
: API key for the mailing service.
API Endpoints The Task Manager API provides the following endpoints:
User Routes:
POST /users
- Register a new user.POST /users/login
- Login and generate an authentication token.POST /users/logout
- Logout and invalidate the current token.POST /users/logoutAll
- Logout from all devices.GET /users/me
- Get user profile.PATCH /users/me
- Update user profile.DELETE /users/me
- Delete user account.
Task Routes:
POST /tasks
- Create a new task.GET /tasks
- Get all tasks.GET /tasks/:id
- Get a specific task.PATCH /tasks/:id
- Update a task.DELETE /tasks/:id
- Delete a task.
To access protected routes, you need to obtain an authentication token by registering a new user or logging in. Include the token in the Authorization header of your requests:
Authorization: Bearer your-auth-token
Unit tests are included in the project to ensure the functionality of the API. You can run the tests using the following command:
npm test
Contributions are welcome! Feel free to open issues or pull requests to improve this project.