Node.js
Run hypequery behind a dedicated Node.js server using Hono.
Node.js
This guide assumes you already have:
- a typed
dbclient - an
analytics/queries.tsfile exportingapi - at least one routed query
If not, start with Manual Installation or Quick Start.
We've simplified the serve API in v0.2. If you're looking for the older builder-first API, see Migrate from v0.1.x Serve API and v0.1.x Serve API.
Install the HTTP runtime
npm install hono @hono/node-server dotenv
npm install -D tsx typescriptMount hypequery inside Hono
Create src/app.ts:
import { Hono } from 'hono';
import { api } from '../analytics/queries.js';
import { createFetchHandler } from '@hypequery/serve';
const hypequery = createFetchHandler(api.handler);
export const app = new Hono();
app.get('/', (c) => c.json({ status: 'ok' }));
app.all('/api/analytics/*', (c) => hypequery(c.req.raw));Start the server
Create src/index.ts:
import 'dotenv/config';
import { serve } from '@hono/node-server';
import { app } from './app.js';
serve({
fetch: app.fetch,
port: Number(process.env.PORT ?? 3000),
});Use Fetch Runtime Integration if you want the same pattern in Workers, Bun, or other Fetch runtimes.