API for managing tasks.
- Typescript - I didnt make it compile to js at all. Just ts straight.
- Express
- Mysql(mysql2)
- Bcrypt(hashing), Jsonwebtoken,
- Express validator for validation
- Nodemon - for easy server restart on change
- Node.js with ts-node for direct typescript execution. It wont compile to js
Requirements
- Nodejs (v18 or higher)
- MySQL
- Git
- Clone repo(git cone repo-url)
- cd task-management-api
- npm i for dependencies
DB_HOST=localhost DB_PORT=3306 DB_USER=root DB_PASSWORD=your_mysql_password DB_NAME=task_manager PORT=3000 JWT_SECRET=your_jwt_secret_key
Create db named task_manager CREATE DATABASE task_manager
Create Users and Tasks Table CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
CREATE TABLE tasks ( id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255) NOT NULL, description TEXT, status ENUM('pending', 'completed') DEFAULT 'pending', due_date DATE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, user_id INT NOT NULL, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE );
I configured npm run dev to run nodemon index.ts API will run on localhost:3000
Register or log in to obtain a JWT token via POST /api/auth/register or POST /api/auth/login. Include the token in the Authorization header for protected routes Authorization: Bearer your_token
POST /api/auth/register - to reg new user req body { "username": "string", max 50 min 3 characters "password": "string" min 6 chars }
POST /api/auth/login - logs you in and gives token req body { "username": "string", "password": "string" } correct response 200 ok { "token": "jwt_token" }
POST /api/tasks - create new task Header Authorization: Bearer jwt_token { "title": "string", "description": "string (max 1000 chars, optional)", "due_date": "string (YYYY-MM-DD, optional)" } correct - 201 response
GET /api/tasks - list of all tasks for users correct response - 200 ok [ { "id": 15, "title": "Fry Egg", "description": "this is a task", "status": "pending", "due_date": "2025-10-07T23:00:00.000Z", "created_at": "2025-11-05T14:43:00.000Z", "updated_at": "2025-11-05T14:43:00.000Z", "user_id": 5 } ]
PUT /api/tasks/:id - updates a task all fields are optional { "title": "string", "description": "string", "status": "pending or completed", "due_date": "string (YYYY-MM-DD) or null" }
-
DELETE /api/tasks/:id - deletes task
-
only /register and /login doesnt need auth
400 - bad request - check req body or http method 404 - task not found 409 - conflict - username taken 500 - server error