Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

Deployment: Node.js, Bun, Deno, Cloudflare Workers

Deployment means running the app on a server where users can reach it. Hono route code is the same on every platform; only the entry point and the commands differ. Not every package is compatible, though: better-sqlite3 and process.env do not exist everywhere.

Node.js

On your own server or VPS, the app is built and started with plain Node.js:

npm ci
npm run build
npm start

npm ci installs packages exactly as listed in package-lock.json, npm run build compiles TypeScript into dist/, and npm start runs dist/index.js. The .env file with real secrets is created right on the server. To restart the app after a crash or a reboot, run it under a process manager such as systemd or pm2, and put nginx with HTTPS in front of it.

Bun

Bun runs TypeScript itself and has a built-in server. Instead of serve() from @hono/node-server, the entry point exports the app:

// src/index.ts
import { Hono } from 'hono'
 
const app = new Hono()
 
app.get('/', (c) => c.text('Hello from Bun'))
 
export default app
bun run src/index.ts

Bun sees an object with a fetch method and starts a server on port 3000. Instead of better-sqlite3, Bun projects usually use the built-in bun:sqlite module with similar methods.

Deno

In Deno, Hono is imported from the JSR registry, and the server is started by a built-in function:

// main.ts
import { Hono } from 'jsr:@hono/hono'
 
const app = new Hono()
 
app.get('/', (c) => c.text('Hello from Deno'))
 
Deno.serve(app.fetch)
deno run --allow-net main.ts

The --allow-net flag lets the program use the network: without explicit permissions Deno gives no access to the network or files.

Cloudflare Workers

Workers is a platform where code runs on Cloudflare servers around the world. The project is created from the separate cloudflare-workers template, and the entry point also exports the app (export default app). Commands:

npm run dev
npm run deploy

The first runs a local copy through the Wrangler tool, the second publishes the worker. Workers have no file system, so a file-based SQLite database will not work: the database is replaced with D1, and variables and secrets arrive in c.env.

What changes when moving

Part of the codeNode.jsBunDenoWorkers
startserve()export default appDeno.serve()export default app
variablesprocess.envprocess.envDeno.envc.env
SQLitebetter-sqlite3bun:sqlitea package from JSR or npmD1

The env(c) function from hono/adapter works everywhere, so routes that use it move without changes.

Common mistake

Running npm run dev on the server. That command is for development: it watches files and compiles TypeScript on the fly, wasting memory and time. In production, build the project with npm run build and run npm start.

Thanks for reading!

Donate to the site — we work hard for you.