A modern, flexible file service built with Hono.js featuring:
- Multi-database support: MongoDB, PostgreSQL, MySQL, or SQLite
- Flexible storage: AWS S3 or local file system
- Serverless-ready: Optimized for serverless deployments
- Type-safe: Full TypeScript with Drizzle ORM
- ποΈ Database Abstraction: Switch between MongoDB, PostgreSQL, MySQL, or SQLite via environment variables
- πΎ Storage Flexibility: Use S3 for cloud storage or local file system for development
- β‘ Modern Stack: Hono.js for performance, Drizzle ORM v1 beta 2 for type safety
- π Type Safety: Full TypeScript coverage with inferred types
- π Serverless Ready: Connection pooling and optimizations for AWS Lambda, Vercel, etc.
- Node.js (v18 or higher)
- pnpm (package manager)
- Database of choice (MongoDB, PostgreSQL, MySQL, or SQLite)
- AWS S3 credentials (if using S3 storage) OR local file system
-
Install dependencies:
pnpm install
-
Create a
.envfile (see Environment Variables section below)
pnpm run devThe server will start at http://localhost:8866
pnpm run build
pnpm run startChoose your database by setting DB_TYPE:
DB_TYPE=mongodb
MONGO_URI=mongodb://localhost:27017/fileserviceDB_TYPE=postgres
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=your_password
DB_NAME=fileserviceDB_TYPE=mysql
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=fileserviceDB_TYPE=sqlite
DB_PATH=./data/fileservice.dbAWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_REGION=us-east-1
S3_BUCKET_NAME=your-bucket-nameLOCAL_PATH=/path/to/local/storageIf LOCAL_PATH is set, the service will use local file system instead of S3.
PORT=8866
NODE_ENV=developmentGET /- API infoGET /api/health- Health check with database and storage status
POST /api/files/upload- Upload a file (multipart/form-data)GET /api/files/download/:fileName- Download a filePOST /api/files/presigned-urls- Generate batch presigned URLs
src/
βββ core/
β βββ services/ # Business logic
β βββ storage/ # Storage abstractions (S3, Local)
β βββ utils/ # Utilities (errors, logger)
βββ server/
β βββ controllers/ # Request handlers
β βββ middleware/ # Hono middleware
β βββ routers/ # Route definitions
βββ db/
β βββ schema.*.ts # Database schemas (per dialect)
β βββ drizzle.ts # Drizzle ORM client
β βββ mongodb-adapter.ts # MongoDB adapter
β βββ factory.ts # Database factory
β βββ repository.ts # Data access layer
βββ config/ # Configuration management
βββ index.ts # Application entry point
pnpm drizzle-kit generatepnpm drizzle-kit migratepnpm drizzle-kit pull- Hono.js - Fast web framework for serverless
- Drizzle ORM v1.0.0-beta.2 - Type-safe ORM with multi-dialect support
- AWS SDK v3 - For S3 integration
- Winston - Logging
- TypeScript - Type safety
- SWC - Fast compilation
- Drizzle ORM for PostgreSQL, MySQL, and SQLite
- Custom MongoDB Adapter with Drizzle-like API
- Unified Repository Layer works across all databases
- S3 Adapter using AWS SDK v3
- Local Adapter for file system storage
- Factory Pattern for runtime switching
- Connection pooling with reuse across warm starts
- Lazy initialization
- Optimized cold start performance
MIT β see LICENSE.