A modest backend for a todo app
This is a simple backend application written in Node.js using Express framework and PostgreSQL as the database. The application provides APIs to manage a to-do list, including creating, updating, toggling completion status, and retrieving to-dos.
- Prerequisites
- Installation
- Configuration
- Running the Application
- API Endpoints
- Database Schema
- License
- Contributing
- Contact
Before you begin, ensure you have met the following requirements:
- Node.js installed on your machine
- PostgreSQL database installed and running
- npm package manager installed
-
Clone the repository:
git clone https://github.com/alzca1/todo-back cd todo-backend
-
Install the dependencies:
npm install
-
Build the application and you'll see a "dist" folder will be created inside the project's folder:
npm run build
-
Create a .env file in the root directory and add your PostgreSQL database configuration:
DB_USER=your_username DB_HOST="localhost" DB_NAME="todo-app" DB_PASSWORD=your_password DB_PORT=5432
-
Ensure your PostgreSQL database is running and the database specified in the .env file exists (if not, create it manually with the name 'todo-app').
-
Start the server:
npm start
-
The server will start on http://localhost:3000. You'll know you're good to go once you see the following messages on your bash console:
Table 'todos' created successfully!
connected to the database...
server running on port 3000
-
URL:
/create-todo
-
Method:
POST
-
Request Body:
{ "title": "Your todo title" }
-
Responses:
201 Created
: Successfully created a to-do item.400 Bad Request
: Title is missing or invalid.500 Internal Server Error
: An error occurred on the server.
-
URL:
/update-todo
-
Method:
PATCH
-
Request Body:
{ "id": "todo_id", "title": "Updated title" }
-
Responses:
201 Created
: Successfully updated the to-do item.400 Bad Request
: Invalid id or title.500 Internal Server Error
: An error occurred on the server.
-
URL:
/toggle-completed
-
Method:
PATCH
-
Request Body:
{ "id": "todo_id", "completed": true }
-
Responses:
201 Created
: Successfully toggled the completion status.400 Bad Request
: Invalid id or completion status.500 Internal Server Error
: An error occurred on the server.
- URL:
/todos
- Method:
GET
- Responses:
200 OK
: Successfully retrieved all to-do items.204 No Content
: No to-do items found.500 Internal Server Error
: An error occurred on the server.
Ensure your PostgreSQL database has the following schema for the to-do items:
CREATE TABLE IF NOT EXISTS todos (
id SERIAL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
completed BOOLEAN NOT NULL DEFAULT FALSE,
"dateCreated" TIMESTAMP NOT NULL DEFAULT NOW(),
"dateCompleted" TIMESTAMP
);
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request for any changes.
If you have any questions or need further assistance, feel free to contact me at alzca1l@gmail.com.