Skip to main content
Netlify is a modern web development platform that provides hosting and serverless functions. Deploy your Hono applications to Netlify with seamless integration.

Quick Start

Create a new Hono project for Netlify:
Select “netlify” as your template when prompted.

Installation

Add Hono to your existing Netlify project:

Basic Usage

Create your API in the netlify/functions directory:
netlify/functions/api.ts
The handle adapter converts your Hono app into a Netlify Function handler.

Catch-All Routes

Handle all routes in a single function using catch-all:
netlify/functions/[[route]].ts

Accessing Netlify Context

Access the Netlify context in your handlers:
netlify/functions/api.ts

Connection Info

Get connection information:

Environment Variables

Access environment variables:
netlify/functions/api.ts
Add environment variables in Netlify:
  1. Go to Site settings → Environment variables
  2. Add your variables
  3. Redeploy your site

Configuration

Create a netlify.toml configuration file:
netlify.toml

Middleware

CORS

netlify/functions/api.ts

Logger

netlify/functions/api.ts

Deployment

1

Install Netlify CLI

2

Login to Netlify

3

Initialize your site

4

Deploy

For production:

Deploy via Git

Connect your Git repository to Netlify:
  1. Push your code to GitHub, GitLab, or Bitbucket
  2. Go to Netlify Dashboard
  3. Click “Add new site” → “Import an existing project”
  4. Select your repository
  5. Configure build settings:
    • Build command: npm run build
    • Publish directory: dist
    • Functions directory: netlify/functions
  6. Deploy
Netlify will automatically deploy on every push to your main branch.

Project Structure

Typical Netlify + Hono project structure:

Edge Functions

Use Netlify Edge Functions for globally distributed compute:
netlify/edge-functions/api.ts
Edge Functions run on Deno at the edge, closer to your users.

Database Integration

Netlify Blobs

netlify/functions/storage.ts

External Databases

Connect to external databases like Supabase, PlanetScale, or MongoDB:
netlify/functions/api.ts

Forms Integration

Handle Netlify Forms:
netlify/functions/form-handler.ts

Best Practices

Use [[route]].ts to handle all routes in a single function for better organization.
Use Edge Functions for globally distributed, low-latency APIs.
Use netlify.toml to configure redirects and rewrites.
Store secrets in Netlify’s environment variables, not in code.

Development

Run locally with Netlify Dev:
This starts a local development server at http://localhost:8888 with hot reload and simulates the production environment.

Performance Tips

  • Use Edge Functions for global distribution
  • Implement caching with Netlify Blobs
  • Optimize function bundle size
  • Use background functions for long-running tasks
  • Enable HTTP/2 Server Push

Resources

Netlify Documentation

Official Netlify documentation

Netlify Functions

Learn about Netlify Functions