A RESTful task management API built with Node.js, Express, and PostgreSQL. Features JWT authentication, rate limiting, and full CRUD operations.
- Runtime: Node.js
- Framework: Express
- Database: PostgreSQL
- Authentication: JWT
- Password hashing: bcryptjs
- Rate limiting: express-rate-limit
task-api/
├── src/
│ ├── config/
│ │ └── db.js
│ ├── middleware/
│ │ ├── auth.js
│ │ └── rateLimiter.js
│ ├── routes/
│ │ ├── auth.routes.js
│ │ └── tasks.routes.js
│ ├── controllers/
│ │ ├── auth.controller.js
│ │ └── tasks.controller.js
│ ├── models/
│ │ └── db.sql
│ └── app.js
└── server.js
- Node.js v18+
- PostgreSQL
- Clone the repository
git clone https://github.com/Ramiro-9/task-api.git
cd task-api- Install dependencies
npm install- Set up environment variables
cp .env.example .envFill in your values in .env.
- Create the database and run the schema
CREATE DATABASE taskdb;Then run the contents of src/models/db.sql in your database.
- Start the server
npm run devPORT=3000
DATABASE_URL=postgresql://user:password@localhost:5432/taskdb
JWT_SECRET=your_secret_key
JWT_EXPIRES_IN=7d
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX=100
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /api/auth/register |
❌ | Register a new user |
| POST | /api/auth/login |
❌ | Login and receive JWT |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/tasks |
✅ | Get all tasks |
| POST | /api/tasks |
✅ | Create a task |
| PUT | /api/tasks/:id |
✅ | Update a task |
| DELETE | /api/tasks/:id |
✅ | Delete a task |
POST /api/auth/register
Content-Type: application/json
{
"email": "user@example.com",
"password": "yourpassword"
}POST /api/auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "yourpassword"
}POST /api/tasks
Authorization: Bearer <token>
Content-Type: application/json
{
"title": "My first task",
"description": "Task description"
}PUT /api/tasks/1
Authorization: Bearer <token>
Content-Type: application/json
{
"completed": true
}CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE tasks (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
title VARCHAR(255) NOT NULL,
description TEXT,
completed BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT NOW()
);MIT