Skip to content

Repository files navigation

Task Manager API

A REST API for user registration, authentication, and personal task management, built with TypeScript, Express, MongoDB, and JWT.

For architecture details and design decisions, see TECHNICAL_DOC.md.

Features

  • User signup and login
  • Password hashing with bcryptjs
  • JWT-based protected routes
  • CRUD operations for personal tasks
  • Tests with Jest + Supertest (in-memory MongoDB)

Prerequisites

  • Node.js 18+
  • npm
  • A MongoDB connection URI

Setup

  1. Install dependencies:

    npm install
  2. Create a .env file in the project root:

    PORT=4040
    MONGODB_URL=<your-mongo-uri>
    JWT_SECRET=<your-jwt-secret>
  3. Start the app in development mode:

    npm run dev

The server runs on http://localhost:4040 by default.

Scripts

Command Description
npm run dev Run the app with ts-node + nodemon
npm run build Compile TypeScript to dist
npm start Run the compiled app
npm test Run the Jest test suite

API Endpoints

User

Method Endpoint Access Description
POST /user/new Public Register a new user
POST /user/login Public Login and receive a JWT

POST /user/new — body:

{
  "name": "Jacob",
  "email": "jacob@example.com",
  "password": "password123",
  "password2": "password123"
}

POST /user/login — body:

{
  "email": "jacob@example.com",
  "password": "password123"
}

Both return a token on success — use it as a Bearer token for the task endpoints below.

Tasks

All task endpoints require the header:

Authorization: Bearer <token>
Method Endpoint Access Description
POST /tasks Protected Create a new task
GET /tasks Protected Get all tasks for the logged-in user
GET /tasks/:taskId Protected Get one task by ID
PUT /tasks/:taskId Protected Update a task
DELETE /tasks/:taskId Protected Delete a task

POST /tasks / PUT /tasks/:taskId — body:

{
  "task": "Exercise",
  "description": "2h Heavyweight Lifting",
  "completed": false
}

PUT accepts a partial body — only send the fields you want to change.

Response format

All responses follow the same shape:

{
  "ok": true,
  "payload": "...",
  "token": "..."
}
  • oktrue on success, false on error
  • payload — the result data or an error message
  • token — only present on register/login responses

Testing

npm test

Tests run against an in-memory MongoDB instance (mongodb-memory-server), so no live database is required.

About

Learning project focused on building a RESTful API that allows users to register, authenticate, and manage personal tasks. The API handles the full task lifecycle: creation, reading, updating, and deletion (CRUD), all protected behind JWT-based authentication. (TypeScript, authentication patterns, testing, and clean API architecture.)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages