Deployment · By Rivtor · Updated
Deploy a Hono Node.js API with PostgreSQL
Deploy Hono on Node.js with its Node server adapter and a PostgreSQL driver that matches that runtime. Bind to the host’s port, keep credentials server-side and validate SQL-backed routes after migrations. Edge-runtime examples are not automatically Node deployment examples.
See the Rivtor deployment workflow →
Choose the Node runtime explicitly
Hono can run in several environments. A Cloudflare Worker binding or edge-specific database client may not exist in a Node container. Identify the runtime used by the app, install its adapter, and remove assumptions that depend on another host’s environment.
For an illustrative Node ESM service with hono, @hono/node-server and pg installed:
import { Hono } from 'hono';
import { serve } from '@hono/node-server';
import pg from 'pg';
const app = new Hono();
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL, max: 3 });
app.get('/ready', async c => {
await pool.query('SELECT 1');
return c.json({ ok: true });
});
serve({ fetch: app.fetch, hostname: '0.0.0.0', port: Number(process.env.PORT ?? 3000) });
This checks only connectivity. Add authentication, validation, a shutdown handler and application migrations for a real service. Choose a production build and start script that work from a clean checkout.
Keep data access on the server
Read DATABASE_URL at runtime in server code. A browser bundle must never contain the connection string. Use bounded pools and parameterized queries; creating a new unbounded pool inside each handler can exhaust the database under traffic.
If the app uses Drizzle or another ORM, commit the migration history and execute the reviewed migration before testing schema-dependent routes. On Rivtor, inspect framework detection and confirm the expected data service is requested. An explicit override may be necessary for a nonstandard directory layout.
Verify from outside the container
Request the public health path, create and read a synthetic record through the app, then restart the API. Test browser origins if a separate frontend calls it. Successful execution on localhost does not test public routing or CORS.
If deployment fails, inspect whether the runtime is loading an edge-only import, whether the adapter is installed in runtime dependencies, and whether the emitted JavaScript exists. Fix the specific mismatch before changing the host or database settings.