Hono + PostgreSQL
Ultrafast web framework for edge and serverless with PostgreSQL.
Overview
Hono is an ultrafast web framework designed specifically for edge computing and serverless environments, built with Web Standard APIs (Request, Response) for maximum portability across JavaScript runtimes including Bun, Deno, Node.js, Cloudflare Workers, and Vercel. Originally created to address the performance limitations of traditional web frameworks in edge environments, Hono features a RegExp-based router that delivers exceptional routing speed while maintaining a small bundle size, making it ideal for latency-sensitive applications deployed at the edge. When combined with PostgreSQL, this stack creates a powerful full-stack solution that leverages PostgreSQL's enterprise-grade ACID compliance, advanced transaction support, and robust JSON/JSONB capabilities alongside Hono's edge-optimized performance characteristics. The PostgreSQL integration provides reliable data persistence with full-text search, geospatial capabilities through PostGIS, and sophisticated query optimization, while Hono handles high-throughput request processing with minimal cold start times. This combination is particularly valuable for developers building modern web applications that require both edge performance and enterprise-grade database capabilities, such as real-time APIs, serverless backends, and globally distributed applications that need consistent data integrity across multiple regions.
Key Features
- RegExp-based ultrafast routing with sub-millisecond request processing optimized for edge deployment
- Web Standard API compatibility enabling deployment across Bun, Deno, Node.js, Cloudflare Workers, and Vercel without code changes
- PostgreSQL ACID compliance with advanced transaction isolation levels for enterprise-grade data integrity
- JSON/JSONB native support in PostgreSQL for hybrid relational-document data models with indexing
- Edge-optimized cold start performance with minimal bundle size for serverless environments
- Full-text search capabilities with ranking and highlighting through PostgreSQL's built-in search functions
- Logical and streaming replication support for multi-region PostgreSQL deployments
- Extensible PostgreSQL type system supporting custom functions and PostGIS geospatial operations
Common Use Cases
- 1Edge-deployed API backends for mobile applications requiring sub-100ms response times globally
- 2Serverless e-commerce platforms needing ACID transactions for payment processing with edge caching
- 3Real-time analytics dashboards processing high-frequency data with PostgreSQL window functions
- 4Multi-tenant SaaS applications leveraging PostgreSQL row-level security and Hono's lightweight routing
- 5Geospatial applications combining PostGIS capabilities with edge-optimized API responses
- 6JAMstack applications requiring fast API routes with complex relational data queries
- 7IoT data collection systems processing sensor data at edge locations with PostgreSQL time-series optimization
Prerequisites
- Docker Desktop or Docker Engine with Docker Compose v2.0+ installed and running
- Minimum 1GB RAM available (256MB for PostgreSQL, additional memory for Hono application)
- Port 3000 available for Hono web server access
- Basic understanding of JavaScript/TypeScript and SQL query syntax
- Familiarity with ORM tools like Drizzle or Prisma for database schema management
- Environment variables configured for DB_NAME, DB_USER, and DB_PASSWORD
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 hono: 3 build: .4 container_name: hono5 environment: 6 DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}7 ports: 8 - "3000:3000"9 depends_on: 10 - postgres11 networks: 12 - hono-network1314 postgres: 15 image: postgres:16-alpine16 environment: 17 POSTGRES_DB: ${DB_NAME}18 POSTGRES_USER: ${DB_USER}19 POSTGRES_PASSWORD: ${DB_PASSWORD}20 volumes: 21 - postgres_data:/var/lib/postgresql/data22 networks: 23 - hono-network2425volumes: 26 postgres_data: 2728networks: 29 hono-network: 30 driver: bridge.env Template
.env
1DB_NAME=hono2DB_USER=hono3DB_PASSWORD=changemeUsage Notes
- 1Docs: https://hono.dev/
- 2Access at http://localhost:3000
- 3Runs on Bun, Deno, Node.js, Cloudflare Workers, Vercel
- 4Web Standard APIs (Request, Response)
- 5Ultrafast routing with RegExp-based router
- 6Use Drizzle or Prisma for database access
Individual Services(2 services)
Copy individual services to mix and match with your existing compose files.
hono
hono:
build: .
container_name: hono
environment:
DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}
ports:
- "3000:3000"
depends_on:
- postgres
networks:
- hono-network
postgres
postgres:
image: postgres:16-alpine
environment:
POSTGRES_DB: ${DB_NAME}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- hono-network
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 hono:5 build: .6 container_name: hono7 environment:8 DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}9 ports:10 - "3000:3000"11 depends_on:12 - postgres13 networks:14 - hono-network1516 postgres:17 image: postgres:16-alpine18 environment:19 POSTGRES_DB: ${DB_NAME}20 POSTGRES_USER: ${DB_USER}21 POSTGRES_PASSWORD: ${DB_PASSWORD}22 volumes:23 - postgres_data:/var/lib/postgresql/data24 networks:25 - hono-network2627volumes:28 postgres_data:2930networks:31 hono-network:32 driver: bridge33EOF3435# 2. Create the .env file36cat > .env << 'EOF'37DB_NAME=hono38DB_USER=hono39DB_PASSWORD=changeme40EOF4142# 3. Start the services43docker compose up -d4445# 4. View logs46docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/hono-postgres/run | bashTroubleshooting
- Connection refused on port 3000: Ensure Hono container built successfully and DATABASE_URL environment variable is properly formatted
- PostgreSQL connection timeout: Verify postgres container is fully initialized before Hono starts, consider adding healthcheck or wait script
- FATAL: database does not exist: Check DB_NAME environment variable matches POSTGRES_DB value in postgres service
- Hono runtime errors about missing dependencies: Verify your Dockerfile includes proper package.json and node_modules installation for chosen runtime
- ORM connection pooling issues: Configure connection pool size appropriately for PostgreSQL max_connections setting in high-load scenarios
- Edge deployment failures: Ensure Hono application uses only Web Standard APIs and avoid Node.js-specific modules for serverless compatibility
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Ad Space
Shortcuts: C CopyF FavoriteD Download