A robust, high-performance Node.js API for seamless file management, powered by Fastify, Drizzle ORM, and Cloudflare R2.
Upload Widget Server is a backend solution designed to handle file uploads efficiently and securely. It solves the complexity of managing file storage, metadata, and retrieval by providing a clean API interface that integrates directly with Cloudflare R2 (S3-compatible storage) and PostgreSQL.
Whether you are building a dashboard, a social platform, or a content management system, this server provides the essential plumbing for your media assets.
- ๐ High-Performance Uploads: Optimized handling of multipart/form-data using Fastify.
- โ๏ธ Cloud Storage Integration: Native support for Cloudflare R2 (via AWS SDK).
- ๐๏ธ Robust Data Management: PostgreSQL database with Drizzle ORM for type-safe queries.
- ๐ Advanced Search & Filtering: Built-in pagination, sorting, and text search capabilities.
- ๐ Data Export: Generate CSV reports of your uploaded assets on the fly.
- ๐ก๏ธ Type Safety: End-to-end type validation with Zod and TypeScript.
- ๐ณ Docker Ready: Containerized environment for easy deployment and development.
Docker - Containerization
Zod - Schema validation
Vitest - Testing framework
Biome - Linting & Formatting
Follow these steps to get your development environment running in less than 5 minutes.
- Node.js (v20+ recommended)
- pnpm (Package Manager)
- Docker & Docker Compose
-
Clone the repository
git clone https://github.com/christopherldo/upload-widget-server.git cd upload-widget-server -
Install dependencies
pnpm install
-
Configure Environment Variables Copy the example file and fill in your credentials (especially Cloudflare R2 details).
cp .env.example .env
-
Start Database (Docker) Run the PostgreSQL container in the background.
docker-compose up -d
-
Run Migrations Apply the database schema.
pnpm db:migrate
Start the server in watch mode:
pnpm devThe server will start at http://localhost:3333.
Access the interactive Swagger/OpenAPI documentation at:
http://localhost:3333/docs
| Command | Description |
|---|---|
pnpm dev |
Starts the development server with hot-reload |
pnpm build |
Builds the project for production |
pnpm test |
Runs the test suite with Vitest |
pnpm db:generate |
Generates SQL migrations from Drizzle schema |
pnpm db:studio |
Opens Drizzle Studio to view/edit data |
Upload an Image:
curl -X POST http://localhost:3333/uploads \
-F "file=@/path/to/your/image.png"Response (201 Created):
// No content (201).
โโโ ๐ docker/ # Docker configuration and init scripts
โโโ ๐ src/
โ โโโ ๐ app/ # Business logic & Use Cases
โ โ โโโ ๐ functions/ # Core functionality (upload, get, export)
โ โโโ ๐ infra/ # Infrastructure layer
โ โ โโโ ๐ db/ # Database setup (Drizzle schemas, migrations)
โ โ โโโ ๐ http/ # HTTP server (Fastify routes, server setup)
โ โ โโโ ๐ storage/ # Storage implementation (S3/R2 client)
โ โโโ ๐ shared/ # Shared utilities (Either pattern, types)
โ โโโ ๐ env.ts # Environment variable validation
โโโ ๐ .env.example # Environment variables template
โโโ ๐ docker-compose.yml # Docker services
โโโ ๐ package.json # Project dependencies
โโโ ๐ drizzle.config.ts # Drizzle ORM config
Based on the current codebase, here are some suggested improvements:
- Authentication: Add JWT or API Key authentication to protect endpoints.
- File Validation: Expand support for other file types (PDF, Docs) and add virus scanning.
- CDN Integration: Directly expose public URLs via a configured CDN domain.