A TypeScript Node.js API project for managing tasks with a PostgreSQL database.
You can find a live demo version of this project deployed using Render here - https://task-tracker-api-2z5y.onrender.com/
In the live demo version, We are using a PostgreSQL database deployed on AWS RDS.
Note - Server may go down occasionally due to inactivity as it's on free tier
Before you begin, ensure you have met the following requirements:
- Node.js and npm installed.
- PostgreSQL database server running.
-
Clone this repository to your local machine:
git clone https://github.com/yourusername/task-tracker-api.git
-
Navigate to the project directory:
cd task-tracker-api
-
Install project dependencies:
npm install
-
Create a PostgreSQL database for the project.
-
Copy the below
.env
file contents to your.env
and configure the database connection details:DATABASE_NAME=yourdbname DATABASE_USERNAME=yourdbusername DATABASE_PASSWORD=yourdbpassword DATABASE_HOST=yourdatabasehost DATABASE_PORT=5432
To create the necessary database tables, run the following migration command:
npm run migrate
You will see the following message upon successful migration
Connected to the database
Migration completed successfully
Disconnected from the database
Start the Node.js server:
npm run dev
By default, the server will run on http://localhost:3000
.
- GET /: Check app status
- Response Example:
{ "message":"App is running on port 3000" }
- Response Example:
-
POST /api/tasks: Create a new task.
- Request Body:
{ "title": "Task Title", "description": "Task Description", "status": "open" }
- Response Example:
{ "status": "success", "data": { "id": 1, "title": "Task Title", "description": "Task Description", "status": "open", "createdAt": "2023-09-28T12:00:00Z", "updatedAt": "2023-09-28T12:00:00Z" } }
- Request Body:
-
PUT /api/tasks/{taskId}: Update a task's status.
- Request Params:
taskId
(integer): ID of the task to update.
- Request Body:
{ "status": "inprogress" }
- Response Example:
{ "status": "success", "data": { "id": 1, "title": "Task Title", "description": "Task Description", "status": "inprogress", "createdAt": "2023-09-28T12:00:00Z", "updatedAt": "2023-09-28T14:00:00Z" } }
- Request Params:
-
GET /api/tasks: Get all tasks with pagination.
- Query Params:
page
(integer, optional): Page number (default: 1).limit
(integer, optional): Number of tasks per page (default: 10).
- Request Example -
/api/tasks?page=1&limit=8
- Response Example:
{ "status": "success", "data": { "totalTasks": 2, "currentPage": 1, "tasks": [ { "id": 1, "title": "Task 1", "description": "Description 1", "status": "open", "createdAt": "2023-09-28T12:00:00Z", "updatedAt": "2023-09-28T12:00:00Z" }, { "id": 2, "title": "Task 2", "description": "Description 2", "status": "completed", "createdAt": "2023-09-28T13:00:00Z", "updatedAt": "2023-09-28T13:00:00Z" } ] } }
- Query Params:
-
GET /api/metrics: Get all task metrics (ungrouped).
- Response Example:
{ "status": "success", "data": { "totalTasks": 50, "openTasks": 20, "inprogressTasks": 15, "completedTasks": 15 } }
- Response Example:
-
GET /api/metrics/{month}: Get task metrics for a specific month.
- Request Params:
month
(string): Month in 'YYYY-MM' format.
- Response Example:
{ "status": "success", "data": { "month": "October 2023", "metrics": { "totalTasks": "1", "openTasks": "0", "inprogressTasks": "0", "completedTasks": "1" } } }
- Request Params:
-
GET /api/metrics/grouped: Get task metrics grouped by month.
- Response Example:
{ "status": "success", "data": [ { "month": "September 2023", "metrics": { "totalTasks": "2", "openTasks": "1", "inprogressTasks": "1", "completedTasks": "0" } }, { "month": "October 2023", "metrics": { "totalTasks": "1", "openTasks": "0", "inprogressTasks": "0", "completedTasks": "1" } } ] }
- Response Example:
For more API details of endpoints and documentation, please refer to the Swagger Documentation section below.
You can access the Swagger documentation to explore and test the API endpoints:
- Local server Swagger UI: http://localhost:3000/api-docs
- Render deployed server Swagger UI: https://task-tracker-api-2z5y.onrender.com/api-docs/