Quickstart

In this guide, you'll learn how to set up a new project with HonoHub, define your Drizzle schema, and generate API endpoints effortlessly.

Prerequisites

Before setting up HonoHub, ensure you have the following:

Setting Up HonoHub

HonoHub is a middleware that seamlessly integrates into your existing setup without imposing any restrictions on your setup or other middlewares. It provides flexibility, allowing you to customize and extend your application as needed.

Install HonoHub

Add the honohub package to your project using your preferred package manager.

npm add honohub

Setting Up HonoHub

Create a new file named hub.config.ts or hub.config.js in the root of your project and add the following configuration:

hub.config.ts

import { neon } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import { defineCollection, defineHub } from "honohub";
import * as schema from "./src/db/schema";

const neonSql = neon("DATABASE_URL");
const db = drizzle(neonSql, { schema });

export default defineHub({
  db,
  collections: [
    defineCollection({
      slug: "todos",
      schema: schema.todos,
    }),
  ],
});

Change the DATABASE_URL with your database URL.

Here we are assuming that you have a schema file in your project that exports a todos schema. You can replace this with your own schema. Here is an example of a schema file:

schema.ts

import { boolean, pgTable, serial, text, timestamp } from "drizzle-orm/pg-core";

export const todos = pgTable("todos", {
  id: serial("id").primaryKey(),
  status: boolean("status").notNull().default(false),
  message: text("message").notNull(),
  createdAt: timestamp("created_at").notNull().defaultNow(),
  updatedAt: timestamp("updated_at").notNull().defaultNow(),
});

Adding HonoHub in your Project

Add HonoHub to your Hono project like any other route:

index.ts

import { Hono } from "hono";
import { createHub } from "honohub";
import hubConfig from "../hub.config";

const app = new Hono().route("/", createHub(hubConfig));

What's next?

Great, you made it! So, what's next?