Skip to content

oginni76/task-management-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task Management REST API

API for managing tasks.

Tech Stack

  • 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

Set Up

Requirements

  • Nodejs (v18 or higher)
  • MySQL
  • Git

Installation

  • Clone repo(git cone repo-url)
  • cd task-management-api
  • npm i for dependencies

Set Up ENV

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

Set Up MYSQL

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 );

Run with npm run dev

I configured npm run dev to run nodemon index.ts API will run on localhost:3000

Auth

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

Endpoints

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

About

Restful api for task management

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published