A REST API for image uploads built with Fastify, TypeScript, PostgreSQL, and Cloudflare R2.
- Image upload to Cloudflare R2 (S3-compatible storage)
- Paginated upload listing with sorting
- CSV export of upload records
- OpenAPI docs via Swagger UI at
/docs
- Runtime: Node.js with TypeScript
- Framework: Fastify
- Database: PostgreSQL + Drizzle ORM
- Storage: Cloudflare R2 (AWS S3 SDK)
- Validation: Zod
- Testing: Vitest
- Node.js 22+
- pnpm
- PostgreSQL instance
- Cloudflare R2 bucket
-
Install dependencies:
pnpm install
-
Create a
.envfile with the required variables:PORT=3333 NODE_ENV=development DATABASE_URL=postgresql://user:password@localhost:5432/dbname CLOUDFLARE_ACCOUNT_ID= CLOUDFLARE_ACCESS_KEY_ID= CLOUDFLARE_SECRET_ACCESS_KEY= CLOUDFLARE_BUCKET= CLOUDFLARE_PUBLIC_URL=
-
Run database migrations:
pnpm db:migrate
-
Start the development server:
pnpm dev
| Method | Path | Description |
|---|---|---|
POST |
/uploads |
Upload an image file |
GET |
/uploads |
List uploads (paginated) |
GET |
/uploads/export |
Export uploads as CSV |
Full interactive docs available at http://localhost:3333/docs.
# Run tests once
pnpm test
# Watch mode
pnpm test:watchTests require a .env.test file with a separate test database URL.
pnpm db:generate # Generate migrations
pnpm db:migrate # Apply migrations
pnpm db:studio # Open Drizzle Studio