Last Updated: 3/7/2026
Node.js
Node.js is an open-source, cross-platform JavaScript runtime environment.
Hono was not designed for Node.js at first. But with a Node.js Adapter it can run on Node.js as well.
INFO: It works on Node.js versions greater than 18.x. The specific required Node.js versions are as follows:
- 18.x => 18.14.1+
- 19.x => 19.7.0+
- 20.x => 20.0.0+
Essentially, you can simply use the latest version of each major release.
1. Setup
A starter for Node.js is available. Start your project with “create-hono” command. Select nodejs template for this example.
npm create hono@latest my-appMove to my-app and install the dependencies.
cd my-app
npm i2. Hello World
Edit src/index.ts:
import { serve } from '@hono/node-server'
import { Hono } from 'hono'
const app = new Hono()
app.get('/', (c) => c.text('Hello Node.js!'))
serve(app)If you want to gracefully shut down the server, write it like this:
const server = serve(app)
// graceful shutdown
process.on('SIGINT', () => {
server.close()
process.exit(0)
})
process.on('SIGTERM', () => {
server.close((err) => {
if (err) {
console.error(err)
process.exit(1)
}
process.exit(0)
})
})3. Run
Run the development server locally. Then, access http://localhost:3000 in your Web browser.
npm run devChange port number
You can specify the port number with the port option.
serve({
fetch: app.fetch,
port: 8787,
})Access the raw Node.js APIs
You can access the Node.js APIs from c.env.incoming and c.env.outgoing.
import { Hono } from 'hono'
import { serve, type HttpBindings } from '@hono/node-server'
type Bindings = HttpBindings & {
/* ... */
}
const app = new Hono<{ Bindings: Bindings }>()
app.get('/', (c) => {
return c.json({
remoteAddress: c.env.incoming.socket.remoteAddress,
})
})
serve(app)Serve static files
You can use serveStatic to serve static files from the local file system.
import { serveStatic } from '@hono/node-server/serve-static'
app.use('/static/*', serveStatic({ root: './' }))
app.use('/favicon.ico', serveStatic({ path: './favicon.ico' }))
app.use('*', serveStatic({ root: './static' }))