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.
- User signup and login
- Password hashing with
bcryptjs - JWT-based protected routes
- CRUD operations for personal tasks
- Tests with Jest + Supertest (in-memory MongoDB)
- Node.js 18+
- npm
- A MongoDB connection URI
-
Install dependencies:
npm install
-
Create a
.envfile in the project root:PORT=4040 MONGODB_URL=<your-mongo-uri> JWT_SECRET=<your-jwt-secret>
-
Start the app in development mode:
npm run dev
The server runs on http://localhost:4040 by default.
| 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 |
| 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.
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.
All responses follow the same shape:
{
"ok": true,
"payload": "...",
"token": "..."
}ok—trueon success,falseon errorpayload— the result data or an error messagetoken— only present on register/login responses
npm testTests run against an in-memory MongoDB instance (mongodb-memory-server), so no live database is required.