Skip to content

Repository files navigation

API Task Manager

A fully functioning REST API for a task management application. Users can register, log in, create projects, add tasks with priorities and due dates, and mark them complete. Built as a backend-only project, tested via Postman and documented with Swagger.

Live URL:https://api-task-manager-production-7780.up.railway.app
API Docs:https://api-task-manager-production-7780.up.railway.app/docs


Tech Stack

  • Runtime: Node.js
  • Framework: Express.js
  • Database: PostgreSQL
  • Query Builder: Knex.js
  • Authentication: JWT (access + refresh tokens)
  • Validation: Zod
  • Testing: Jest + Supertest
  • Containerisation: Docker + Docker Compose
  • Deployment: Railway
  • Documentation: Swagger UI (OpenAPI 3.0)

Features

  • User registration and login with bcrypt password hashing
  • JWT-based authentication with short-lived access tokens (15 min) and refresh tokens (7 days)
  • Refresh token rotation and logout
  • Full CRUD for projects and tasks
  • Task priorities (low, medium, high), due dates, and completion toggling
  • Ownership enforcement — users can only access their own data
  • Input validation on all POST and PATCH routes
  • Centralised error handling
  • Offset pagination on list endpoints
  • Rate limiting on auth routes
  • Secure HTTP headers via Helmet
  • Integration tests for auth and resource endpoints
  • Full Docker Compose setup for local development

Getting Started

Prerequisites

  • Node.js (v20+)
  • Docker and Docker Compose

Running Locally with Docker

  1. Clone the repository:
git clone https://github.com/your-username/api-task-manager.git
cd api-task-manager
  1. Create a .env file in the root of the project (see Environment Variables below)

  2. Start the app and database:

docker compose up --build

Migrations run automatically on startup. The API will be available at http://localhost:3000.

Running Locally without Docker

  1. Make sure PostgreSQL is running and you have a database created

  2. Install dependencies:

npm install
  1. Create a .env file (see Environment Variables below)

  2. Run migrations:

npx knex migrate:latest
  1. Start the server:
npm run dev

Running Tests

Tests run against a separate test database. Make sure your .env.test file is configured before running.

npm test

Environment Variables

Create a .env file in the root of the project with the following variables:

VariableDescriptionExample
NODE_ENVEnvironment namedevelopment
DB_HOSTDatabase hostlocalhost
DB_USERDatabase useradmin
DB_PASSWORDDatabase passwordpassword
DB_NAMEDatabase nametask_manager
DB_PORTDatabase port5432
JWT_SECRETSecret key for signing JWTsyour_random_secret

For the test environment, create a .env.test file with the same variables but pointing at your test database (DB_NAME=task_manager_test).

To generate a secure JWT_SECRET:

node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"

API Endpoints

Auth

MethodEndpointDescriptionAuth Required
POST/auth/registerRegister a new userNo
POST/auth/loginLog in and receive tokensNo
POST/auth/refreshGet a new access tokenNo
POST/auth/logoutInvalidate refresh tokenNo
GET/auth/meGet current userYes

Projects

MethodEndpointDescriptionAuth Required
POST/projectsCreate a projectYes
GET/projectsList all projectsYes
GET/projects/:idGet a single projectYes
PATCH/projects/:idUpdate a project nameYes
DELETE/projects/:idDelete a project and its tasksYes

Tasks

MethodEndpointDescriptionAuth Required
POST/projects/:projectId/tasksCreate a taskYes
GET/projects/:projectId/tasksList all tasks for a projectYes
GET/projects/:projectId/tasks/:idGet a single taskYes
PATCH/projects/:projectId/tasks/:idUpdate a taskYes
DELETE/projects/:projectId/tasks/:idDelete a taskYes
PATCH/projects/:projectId/tasks/:id/completeToggle task completionYes

All protected routes require an Authorization header in the format:

Authorization: Bearer <access_token>

Pagination

List endpoints support optional query parameters:

GET /projects?page=1&limit=20
GET /projects/:projectId/tasks?page=1&limit=20

Project Structure

src/
app.js # Express app setup
server.js # Server entry point
db.js # Knex database connection
middleware/
auth.js # JWT authentication middleware
errorHandler.js # Centralised error handler
limiter.js # Rate limiter
routes/
auth/ # Auth routes (register, login, refresh, logout)
projects/ # Project CRUD routes
tasks/ # Task CRUD routes (nested under projects)
schemas/
projects.js # Zod validation schemas for projects
tasks.js # Zod validation schemas for tasks
tests/
setup.js # Jest setup (migrations before tests)
auth.test.js # Auth endpoint integration tests
projects.test.js # Project endpoint integration tests
tasks.test.js # Task endpoint integration tests

About

A REST API for a task management app built with Node.js, Express, PostgreSQL and JWT authentication

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages