The server handles image uploads using Node.js, PostgreSQL, and Cloudflare R2. It provides routes for uploading, listing, and exporting files in CSV format, leveraging PostgreSQL cursors and Node.js streams for efficient data handling. The system includes validation, error management, testing, and CI workflows to ensure reliability and scalability.
This project is a web application that runs using pnpm as a package manager and can be containerized using Docker. It includes Fastify for handling HTTP requests and Drizzle ORM for database management.
Before running the project, ensure you have the following installed:
- Node.js (Recommended version: LTS)
- pnpm (Package Manager)
- Docker (For containerization)
- Docker Compose (For easier container management)
This project requires Node.js version 20.18.2. The .nvmrc file ensures the correct version is used. If you use nvm, you can run the following command to automatically switch to the required version:
nvm useIf you don’t have the correct version installed, run:
nvm install 20.18.2Clone the repository and install dependencies using pnpm:
pnpm installTo start the development server, use:
pnpm run devTo run the project inside a Docker container using Docker Compose, follow these steps:
-
Ensure Docker and Docker Compose are installed.
-
Create a
docker-compose.ymlfile with the following content:services: pg: image: bitnami/postgresql:latest ports: - "5433:5432" environment: - POSTGRES_USER=docker - POSTGRES_PASSWORD=docker - POSTGRES_DB=upload_test volumes: - "./docker:/docker-entrypoint-initdb.d"
-
Run the container with:
docker-compose up
-
Stop the container with:
docker-compose down
If using Docker Desktop, follow these steps:
- Open Docker Desktop.
- Click on Containers > Add Container.
- Select Build from Source and point it to your project directory.
- Configure the necessary ports (e.g.,
3333:3333). - Start the container.
The project uses the following environment variables:
PORT=3333
NODE_ENV=development
# Database
DATABASE_URL="postgresql://docker:docker@localhost:5432/upload"
# CloudFlare R2
CLOUDFLARE_ACCOUNT_ID=""
CLOUDFLARE_ACCESS_KEY_ID=""
CLOUDFLARE_SECRET_ACCESS_KEY=""
CLOUDFLARE_BUCKET=""
CLOUDFLARE_PUBLIC_URL="https://pub-secret"Ensure you create a .env file with these variables before running the project.
The project includes Drizzle ORM for database migrations. Use the following commands:
- Generate migration files:
pnpm run db:generate
- Apply migrations:
pnpm run db:migrate
- Start Drizzle Studio (visual tool):
pnpm run db:studio
Run tests using Vitest:
pnpm run testFor watch mode:
pnpm run test:watchFeel free to open issues or submit pull requests.
This project is licensed under [Your License].