This is a task management API built using Node.js, Express, SQLite3, and JWT for authentication. The API allows user registration, login, task management (CRUD operations), and role-based access control (Admin and Normal User).
- User Registration: New users can register by providing a username, password, email, and phone number.
- Login: Users can log in using their email and password to receive a JWT token.
- Task Management:
- Admins can create, read, update, and delete tasks.
- Normal users can mark tasks as
pendingordone.
- Role-Based Access Control: Admins have higher privileges than normal users.
- JWT Authentication: Secures API routes and allows only authenticated users to perform actions.
- Node.js: JavaScript runtime.
- Express.js: Web framework for Node.js.
- SQLite3: Database for storing users and tasks.
- JWT: JSON Web Token for authentication and securing routes.
- bcryptjs: For hashing and verifying passwords.
To get started with the project, follow these steps:
- Clone the repository:
git clone <repository-url> - Navigate to the project directory:
cd task-management-api - Install the dependencies:
npm install - Create a
.envfile in the root directory and add the following environment variables:PORT=6060 DB_PATH=./database/db.sqlite3 JWT_SECRET=your_jwt_secret_key - Run the database migration to create the necessary tables:
npm run migrate - Start the server:
npm start
The API should now be running at http://localhost:6060.
JWT Token is required for all endpoints except /register and /login. Admins can perform CRUD operations on tasks. Normal users can only mark tasks as pending or done.
The API uses SQLite3 to store user and task data. You can modify the database path in the .env file as needed.
| Field | Type | Description |
|---|---|---|
| id | INT | Primary Key (Auto Increment) |
| username | TEXT | Unique Username |
| password | TEXT | Hashed password |
| TEXT | Unique Email | |
| phone | TEXT | Unique Phone Number |
| role | TEXT | User role (admin/normal user) |
| Field | Type | Description |
|---|---|---|
| id | INT | Primary Key (Auto Increment) |
| title | TEXT | Task title |
| description | TEXT | Task description |
| status | TEXT | Task status (pending/done) |
- Add pagination for tasks.
- Implement search and filtering by task status.
- Improve error handling and validation.
This project is open-source and available under the MIT License
