https://github.com/ruslanpashkov/todo-service
💩
https://github.com/ruslanpashkov/todo-service
Last synced: 4 months ago
JSON representation
💩
- Host: GitHub
- URL: https://github.com/ruslanpashkov/todo-service
- Owner: ruslanpashkov
- License: mit
- Created: 2024-11-27T02:19:22.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-11-27T02:29:54.000Z (6 months ago)
- Last Synced: 2024-12-27T23:58:07.545Z (5 months ago)
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fastify Todo API
A one-file todo API with Fastify and PostgreSQL. Has basic stuff like rate limiting, CORS, and handles shutdowns properly. Nothing fancy - it just works.
> P.S. Yes, it's all in one file. No, we're not sorry.
## API Endpoints
- `GET /health` - Health check endpoint
- `GET /todos` - Retrieve all todos
- `POST /todos` - Create a new todo
- `PUT /todos/:id` - Update an existing todo
- `DELETE /todos/:id` - Delete a todo## Prerequisites
- Node.js (v20 or higher)
- PostgreSQL database
- npm or yarn## Environment Variables
Create a `.env` file in the root directory with the following variables:
```env
NODE_ENV=development
PORT=3000
PGUSER=your_db_user
PGHOST=your_db_host
PGDATABASE=your_db_name
PGPASSWORD=your_db_password
PGPORT=5432
CLIENT_URL=http://localhost:3000
```## Installation
```bash
# Install dependencies
npm install# Start the server
npm start
```## Database Schema
Ensure your PostgreSQL database has the following table:
```sql
CREATE TABLE todos (
id SERIAL PRIMARY KEY,
title TEXT NOT NULL,
completed BOOLEAN DEFAULT FALSE
);
```## Production Considerations
- Rate limiting is automatically enabled in production
- SSL is enforced for database connections
- CORS is restricted to the specified CLIENT_URL
- Logging is set to 'info' level with minimal request details## License
[MIT License](LICENSE)