new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Hono · all subjects

app

149 notes in this subject, read out of this brain and free to use. This is page 3 of 3.

serveStatic path option for single files

Use the path option in serveStatic to serve a single file by its path. Example: serveStatic({ path: './favicon.ico' }) serves the favicon file.

serveStatic rewriteRequestPath example

Example of using rewriteRequestPath to map HTTP requests to different directories: app.get( '/static/*', serveStatic({ root: './', rewriteRequestPath: (path) => path.replace(/^\/static/, '/statics'), }) )

HTTP/2 unencrypted support on Node.js

To run Hono on unencrypted HTTP/2 in Node.js, pass createServer from 'node:http2' to the serve() function: import { createServer } from 'node:http2' const server = serve({ fetch: app.fetch, createServer, })

HTTP/2 encrypted support on Node.js

To run Hono on encrypted HTTP/2 in Node.js, pass createSecureServer from 'node:http2' to serve() with serverOptions containing the key and cert: import { createSecureServer } from 'node:http2' import { readFileSync } from 'node:fs' const server = serve({ fetch: app.fetch, createServer: createSecureServer, serverOptions: { key: readFileSync('localhost-privkey.pem'), cert: readFileSync('localhost-cert.pem'), }, })

Create Hono project with Node.js template

Use 'create-hono' to scaffold a new Node.js project. Run 'npm create hono@latest my-app' and select the 'nodejs' template. Other package managers are supported: yarn, pnpm, bun, and deno.

Example Dockerfile for Node.js Hono deployment

Example multi-stage Dockerfile for deploying a Hono Node.js application: FROM node:22-alpine AS base FROM base AS builder RUN apk add --no-cache gcompat WORKDIR /app COPY package*json tsconfig.json src ./ RUN npm ci && \ npm run build && \ npm prune --production FROM base AS runner WORKDIR /app RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 hono COPY --from=builder --chown=hono:nodejs /app/node_modules /app/node_modules COPY --from=builder --chown=hono:nodejs /app/dist /app/dist COPY --from=builder --chown=hono:nodejs /app/package.json /app/package.json USER hono EXPOSE 3000 CMD ["node", "/app/dist/index.js"]

Use app.route() for larger applications

For larger applications with multiple endpoints, create separate Hono app instances in separate files (e.g., authors.ts, books.ts) and mount them using app.route('/path', subApp). This avoids RoR-like controllers while organizing code by domain.

Export AppType for RPC with app.route()

When using app.route() with RPC features, export the type of the app: export type AppType = typeof app. This allows the RPC client (hc) to receive correct types. Pass the type to hc like: const client = hc<AppType>('http://localhost').

create-hono command-line arguments must follow --

When using npm create or npx, arguments intended for the create-hono initializer script must be placed after --. Anything after -- is forwarded to the initializer.

--template argument for create-hono

The --template argument selects a starter template and skips the interactive template prompt. Templates include names like bun, cloudflare-workers, vercel, and others.

--install argument for create-hono

The --install argument automatically installs dependencies after the template is created.

--pm argument for create-hono

The --pm argument specifies which package manager to run when installing dependencies. Common values are npm, pnpm, and yarn.

--offline argument for create-hono

The --offline argument uses the local cache or templates instead of fetching the latest remote templates. This is useful for offline environments or deterministic local runs.

create-hono with npm requires -- before arguments

Example: npm create hono@latest my-app -- --template cloudflare-workers forwards the --template argument to create-hono.

create-hono with yarn does not require --

Example: yarn create hono my-app --template cloudflare-workers selects the Cloudflare Workers template without needing -- before the argument.

create-hono with pnpm does not require --

Example: pnpm create hono@latest my-app --template cloudflare-workers selects the Cloudflare Workers template without needing -- before the argument.

create-hono with bun does not require --

Example: bun create hono@latest my-app --template cloudflare-workers selects the Cloudflare Workers template without needing -- before the argument.

create-hono with deno

Example: deno init --npm hono@latest my-app --template cloudflare-workers selects the Cloudflare Workers template with deno.

Non-interactive create-hono with vercel template

Example: npm create hono@latest my-app -- --template vercel --pm npm --install creates my-app using the vercel template, installs dependencies using npm, and skips interactive prompts.

create-hono offline mode with deno template

Example: pnpm create hono@latest my-app --template deno --offline uses the offline cache with the deno template and does not require network access.

Hono does not maintain official Renovate configuration

The Hono team does not currently maintain Renovate configuration. For automated dependency updates, use third-party renovate-config such as shinGangan/renovate-config-hono instead.

How to use third-party Renovate config for Hono

Add the following to your renovate.json file to use the third-party renovate-config-hono: extend the configuration with "github>shinGangan/renovate-config-hono". See the renovate-config-hono repository for more details.

factory.createApp() method

factory.createApp() creates an instance of Hono with proper types inherited from the factory's Env type. This avoids redundant type definitions compared to new Hono<Env>().

Hono use cases

Hono is suitable for: building Web APIs, proxy of backend servers, front of CDN, edge applications, base server for a library, and full-stack applications.

TypeScript support in Hono

Hono is written in TypeScript and provides first-class TypeScript support with literal types for path parameters.

hono/tiny preset size

The hono/tiny preset is under 14KB when minified. Middleware and adapters are bundled only when used.

Hono quick start commands

To quickly create a new Hono project, use one of these commands: npm create hono@latest (npm), yarn create hono (yarn), pnpm create hono@latest (pnpm), bun create hono@latest (bun), or deno init --npm hono@latest (deno).

Hono meaning and tagline

Hono means flame in Japanese. It is a small, simple, and ultrafast web framework built on Web Standards.

Minimal Hono example

A basic Hono application that responds with 'Hono!' to GET requests on the root path: import { Hono } from 'hono' const app = new Hono() app.get('/', (c) => c.text('Hono!')) export default app

Give your agent this brain