A simple and robust Task Management RESTful API built with Express.js and PostgreSQL. This API allows users to create, read, update, delete, and search tasks with support for pagination and filtering.
- Create tasks
- Fetch all tasks with pagination and search
- Retrieve tasks by ID
- Update tasks by ID
- Delete tasks by ID
- Built-in input validation middleware
- Uses environment variables for database configuration
- Database connection test
- Node.js
- Express.js
- PostgreSQL
- pg (node-postgres)
- dotenv
Clone the repository:
git clone https://github.com/gh-aam/task-management-api-2.gitGo to project directory:
cd task-management-api-2Install dependencies:
npm installCreate a .env file in the root directory and configure your PostgreSQL credentials:
PGUSER=your_postgres_username
PGHOST=localhost
PGDATABASE=your_posgres_database_name
PGPASSWORD=your_postgres_password
PGPORT=5432Create the tasks table in your PostgreSQL database:
CREATE TABLE tasks (
id SERIAL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
description TEXT,
completed BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);Start the server:
npm startVisit http://localhost:3000 to verify the server is running.
GET / - Welcome message
POST /tasks - Create a new task
GET /tasks - Get all tasks with pagination and search
GET /tasks/:id - Get a single task by ID
PUT /tasks/:id - Update a task by ID
DELETE /tasks/:id - Delete a task by ID