A simple TODO API built with Node.js, Express, and PostgreSQL.
- User registration and authentication.
- Create, update, delete, and list TODO items.
- Persistent data storage using PostgreSQL.
- Docker Compose setup for local development.
Before you begin, ensure you have met the following requirements:
- Node.js and npm installed.
- Docker and Docker Compose installed if you plan to use the provided Docker setup.
- PostgreSQL or a Dockerized PostgreSQL instance.
- Clone the repository:
git clone https://github.com/theakashshukla/todo-api.git
- Change to the project directory:
cd todo-api
- Install project dependencies:
npm install
- Create a
.env
file in the project root and configure your environment variables. Here's an example:
PORT=3000
POSTGRES_URL=postgres://postgres:your_password@db:5432/your_database
JWT_SECRET=your_secret_key
- Start the application:
npm start
- Access the application at
http://localhost:3000
.
- Register a new user by sending a POST request to
/api/auth/register
. - Obtain a JWT token by sending a POST request to
/api/auth/login
with your user credentials. - Use the JWT token in the
Authorization
header of your requests to protected routes.
- POST /api/auth/register: Register a new user.
{
"username": "newuser",
"email": "newuser@example.com",
"password": "password"
}
POST /api/auth/login: Authenticate a user and get a JWT token.
{
"email": "newuser@example.com",
"password": "password"
}
{
"title": "New Task",
"description": "A description of the task",
"completed": false
}
{
"title": "Updated Task",
"description": "Updated description",
"completed": true
}
You can run this application using Docker Compose. Make sure you have Docker and Docker Compose installed, then use the provided docker-compose.yml to set up the application and PostgreSQL database.
Save the docker-compose.yml file to your project directory.
Update the .env file with the PostgreSQL configuration.
Run the application:
docker-compose up
The application should be accessible at http://localhost:3000.