Skip to content

Hono + Cloudflare Workers, Neon Postgres, & Drizzle ORM

Notifications You must be signed in to change notification settings

michaelshimeles/hono-starter-kit

Repository files navigation

Hono Backend Starter Kit

A modern, high-performance backend starter template built with Hono, featuring PostgreSQL integration with Drizzle ORM and deployment ready for Cloudflare Workers.

Features

  • Hono Framework: Ultra-fast web framework for edge computing
  • Database Integration: PostgreSQL support with Drizzle ORM
  • Type Safety: Full TypeScript support with Zod validation
  • Edge Ready: Configured for Cloudflare Workers deployment
  • Migration Tools: Database migrations with Drizzle Kit
  • Modern Stack: Uses latest versions of all dependencies

Prerequisites

  • Bun Runtime
  • Node.js (v18 or later)
  • PostgreSQL database (I recommend Neon for serverless PostgreSQL)
  • Cloudflare account (for deployment)

Getting Started

  1. Clone the repository:
git clone https://github.com/michaelshimeles/hono-backend-sync
cd hono-backend
  1. Install dependencies:
bun install
  1. Set up environment variables:
    • Copy .dev.vars.example to .dev.vars
    • Add your database URL:
DATABASE_URL=your_postgresql_connection_string
  1. Run database migrations:
npx drizzle-kit generate
npx drizzle-kit push
  1. Start the development server:
bun run dev

The server will start on http://localhost:8787

Project Structure

hono-backend/
├── src/
│   ├── index.ts        # Main application entry
│   └── db/
│       └── schema.ts   # Database schema definitions
├── drizzle/            # Database migrations
├── .dev.vars.example   # Example environment variables
├── drizzle.config.ts   # Drizzle ORM configuration
├── migrate.ts          # Migration script
├── wrangler.toml       # Cloudflare Workers configuration
└── package.json

Available Scripts

  • bun run dev - Start development server with Wrangler
  • bun run deploy - Deploy to Cloudflare Workers
  • npx drizzle-kit generate - Generate database migrations
  • npx drizzle-kit push - Create table(s)

Database Schema

The starter includes a sample products table with the following schema:

products {
  id: serial (primary key)
  name: text
  description: text
  price: double precision
}

API Endpoints

  • GET / - Fetch all products from the database

All endpoints use Zod for request validation.

Tech Stack

Deployment

This template is configured for deployment to Cloudflare Workers:

bun run deploy

Make sure to set up your environment variables in your Cloudflare Workers dashboard.

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Hono + Cloudflare Workers, Neon Postgres, & Drizzle ORM

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published