{"id":15723253,"url":"https://github.com/honojs/node-server","last_synced_at":"2026-03-05T04:04:32.226Z","repository":{"id":59085163,"uuid":"535328171","full_name":"honojs/node-server","owner":"honojs","description":"Node.js Server for Hono","archived":false,"fork":false,"pushed_at":"2026-02-15T14:37:47.000Z","size":516,"stargazers_count":592,"open_issues_count":44,"forks_count":84,"subscribers_count":5,"default_branch":"main","last_synced_at":"2026-02-27T16:53:09.655Z","etag":null,"topics":["hono","http-server","nodejs","server"],"latest_commit_sha":null,"homepage":"https://hono.dev","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/honojs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-09-11T14:45:55.000Z","updated_at":"2026-02-24T15:38:06.000Z","dependencies_parsed_at":"2025-12-08T15:04:44.591Z","dependency_job_id":null,"html_url":"https://github.com/honojs/node-server","commit_stats":{"total_commits":190,"total_committers":37,"mean_commits":5.135135135135135,"dds":"0.34736842105263155","last_synced_commit":"590fe6cef8a795ea10c300033387f13ed31e144f"},"previous_names":[],"tags_count":84,"template":false,"template_full_name":null,"purl":"pkg:github/honojs/node-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/honojs%2Fnode-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/honojs%2Fnode-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/honojs%2Fnode-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/honojs%2Fnode-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/honojs","download_url":"https://codeload.github.com/honojs/node-server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/honojs%2Fnode-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29966696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T09:33:09.965Z","status":"ssl_error","status_checked_at":"2026-03-01T09:25:48.915Z","response_time":124,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hono","http-server","nodejs","server"],"created_at":"2024-10-03T22:10:50.542Z","updated_at":"2026-03-05T04:04:32.209Z","avatar_url":"https://github.com/honojs.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Node.js Adapter for Hono\n\nThis adapter `@hono/node-server` allows you to run your Hono application on Node.js.\nInitially, Hono wasn't designed for Node.js, but with this adapter, you can now use Hono on Node.js.\nIt utilizes web standard APIs implemented in Node.js version 18 or higher.\n\n## Benchmarks\n\nHono is 3.5 times faster than Express.\n\nExpress:\n\n```txt\n$ bombardier -d 10s --fasthttp http://localhost:3000/\n\nStatistics        Avg      Stdev        Max\n  Reqs/sec     16438.94    1603.39   19155.47\n  Latency        7.60ms     7.51ms   559.89ms\n  HTTP codes:\n    1xx - 0, 2xx - 164494, 3xx - 0, 4xx - 0, 5xx - 0\n    others - 0\n  Throughput:     4.55MB/s\n```\n\nHono + `@hono/node-server`:\n\n```txt\n$ bombardier -d 10s --fasthttp http://localhost:3000/\n\nStatistics        Avg      Stdev        Max\n  Reqs/sec     58296.56    5512.74   74403.56\n  Latency        2.14ms     1.46ms   190.92ms\n  HTTP codes:\n    1xx - 0, 2xx - 583059, 3xx - 0, 4xx - 0, 5xx - 0\n    others - 0\n  Throughput:    12.56MB/s\n```\n\n## Requirements\n\nIt works on Node.js versions greater than 18.x. The specific required Node.js versions are as follows:\n\n- 18.x =\u003e 18.14.1+\n- 19.x =\u003e 19.7.0+\n- 20.x =\u003e 20.0.0+\n\nEssentially, you can simply use the latest version of each major release.\n\n## Installation\n\nYou can install it from the npm registry with `npm` command:\n\n```sh\nnpm install @hono/node-server\n```\n\nOr use `yarn`:\n\n```sh\nyarn add @hono/node-server\n```\n\n## Usage\n\nJust import `@hono/node-server` at the top and write the code as usual.\nThe same code that runs on Cloudflare Workers, Deno, and Bun will work.\n\n```ts\nimport { serve } from '@hono/node-server'\nimport { Hono } from 'hono'\n\nconst app = new Hono()\napp.get('/', (c) =\u003e c.text('Hono meets Node.js'))\n\nserve(app, (info) =\u003e {\n  console.log(`Listening on http://localhost:${info.port}`) // Listening on http://localhost:3000\n})\n```\n\nFor example, run it using `ts-node`. Then an HTTP server will be launched. The default port is `3000`.\n\n```sh\nts-node ./index.ts\n```\n\nOpen `http://localhost:3000` with your browser.\n\n## Options\n\n### `port`\n\n```ts\nserve({\n  fetch: app.fetch,\n  port: 8787, // Port number, default is 3000\n})\n```\n\n### `createServer`\n\n```ts\nimport { createServer } from 'node:https'\nimport fs from 'node:fs'\n\n//...\n\nserve({\n  fetch: app.fetch,\n  createServer: createServer,\n  serverOptions: {\n    key: fs.readFileSync('test/fixtures/keys/agent1-key.pem'),\n    cert: fs.readFileSync('test/fixtures/keys/agent1-cert.pem'),\n  },\n})\n```\n\n### `overrideGlobalObjects`\n\nThe default value is `true`. The Node.js Adapter rewrites the global Request/Response and uses a lightweight Request/Response to improve performance. If you don't want to do that, set `false`.\n\n```ts\nserve({\n  fetch: app.fetch,\n  overrideGlobalObjects: false,\n})\n```\n\n### `autoCleanupIncoming`\n\nThe default value is `true`. The Node.js Adapter automatically cleans up (explicitly call `destroy()` method) if application is not finished to consume the incoming request. If you don't want to do that, set `false`.\n\nIf the application accepts connections from arbitrary clients, this cleanup must be done otherwise incomplete requests from clients may cause the application to stop responding. If your application only accepts connections from trusted clients, such as in a reverse proxy environment and there is no process that returns a response without reading the body of the POST request all the way through, you can improve performance by setting it to `false`.\n\n```ts\nserve({\n  fetch: app.fetch,\n  autoCleanupIncoming: false,\n})\n```\n\n## Middleware\n\nMost built-in middleware also works with Node.js.\nRead [the documentation](https://hono.dev/middleware/builtin/basic-auth) and use the Middleware of your liking.\n\n```ts\nimport { serve } from '@hono/node-server'\nimport { Hono } from 'hono'\nimport { prettyJSON } from 'hono/pretty-json'\n\nconst app = new Hono()\n\napp.get('*', prettyJSON())\napp.get('/', (c) =\u003e c.json({ 'Hono meets': 'Node.js' }))\n\nserve(app)\n```\n\n## Serve Static Middleware\n\nUse Serve Static Middleware that has been created for Node.js.\n\n```ts\nimport { serveStatic } from '@hono/node-server/serve-static'\n\n//...\n\napp.use('/static/*', serveStatic({ root: './' }))\n```\n\nIf using a relative path, `root` will be relative to the current working directory from which the app was started.\n\nThis can cause confusion when running your application locally.\n\nImagine your project structure is:\n\n```\nmy-hono-project/\n  src/\n    index.ts\n  static/\n    index.html\n```\n\nTypically, you would run your app from the project's root directory (`my-hono-project`),\nso you would need the following code to serve the `static` folder:\n\n```ts\napp.use('/static/*', serveStatic({ root: './static' }))\n```\n\nNotice that `root` here is not relative to `src/index.ts`, rather to `my-hono-project`.\n\n### Options\n\n#### `rewriteRequestPath`\n\nIf you want to serve files in `./.foojs` with the request path `/__foo/*`, you can write like the following.\n\n```ts\napp.use(\n  '/__foo/*',\n  serveStatic({\n    root: './.foojs/',\n    rewriteRequestPath: (path: string) =\u003e path.replace(/^\\/__foo/, ''),\n  })\n)\n```\n\n#### `onFound`\n\nYou can specify handling when the requested file is found with `onFound`.\n\n```ts\napp.use(\n  '/static/*',\n  serveStatic({\n    // ...\n    onFound: (_path, c) =\u003e {\n      c.header('Cache-Control', `public, immutable, max-age=31536000`)\n    },\n  })\n)\n```\n\n#### `onNotFound`\n\nThe `onNotFound` is useful for debugging. You can write a handle for when a file is not found.\n\n```ts\napp.use(\n  '/static/*',\n  serveStatic({\n    root: './non-existent-dir',\n    onNotFound: (path, c) =\u003e {\n      console.log(`${path} is not found, request to ${c.req.path}`)\n    },\n  })\n)\n```\n\n#### `precompressed`\n\nThe `precompressed` option checks if files with extensions like `.br` or `.gz` are available and serves them based on the `Accept-Encoding` header. It prioritizes Brotli, then Zstd, and Gzip. If none are available, it serves the original file.\n\n```ts\napp.use(\n  '/static/*',\n  serveStatic({\n    precompressed: true,\n  })\n)\n```\n\n## ConnInfo Helper\n\nYou can use the [ConnInfo Helper](https://hono.dev/docs/helpers/conninfo) by importing `getConnInfo` from `@hono/node-server/conninfo`.\n\n```ts\nimport { getConnInfo } from '@hono/node-server/conninfo'\n\napp.get('/', (c) =\u003e {\n  const info = getConnInfo(c) // info is `ConnInfo`\n  return c.text(`Your remote address is ${info.remote.address}`)\n})\n```\n\n## Accessing Node.js API\n\nYou can access the Node.js API from `c.env` in Node.js. For example, if you want to specify a type, you can write the following.\n\n```ts\nimport { serve } from '@hono/node-server'\nimport type { HttpBindings } from '@hono/node-server'\nimport { Hono } from 'hono'\n\nconst app = new Hono\u003c{ Bindings: HttpBindings }\u003e()\n\napp.get('/', (c) =\u003e {\n  return c.json({\n    remoteAddress: c.env.incoming.socket.remoteAddress,\n  })\n})\n\nserve(app)\n```\n\nThe APIs that you can get from `c.env` are as follows.\n\n```ts\ntype HttpBindings = {\n  incoming: IncomingMessage\n  outgoing: ServerResponse\n}\n\ntype Http2Bindings = {\n  incoming: Http2ServerRequest\n  outgoing: Http2ServerResponse\n}\n```\n\n## Direct response from Node.js API\n\nYou can directly respond to the client from the Node.js API.\nIn that case, the response from Hono should be ignored, so return `RESPONSE_ALREADY_SENT`.\n\n\u003e [!NOTE]\n\u003e This feature can be used when migrating existing Node.js applications to Hono, but we recommend using Hono's API for new applications.\n\n```ts\nimport { serve } from '@hono/node-server'\nimport type { HttpBindings } from '@hono/node-server'\nimport { RESPONSE_ALREADY_SENT } from '@hono/node-server/utils/response'\nimport { Hono } from 'hono'\n\nconst app = new Hono\u003c{ Bindings: HttpBindings }\u003e()\n\napp.get('/', (c) =\u003e {\n  const { outgoing } = c.env\n  outgoing.writeHead(200, { 'Content-Type': 'text/plain' })\n  outgoing.end('Hello World\\n')\n\n  return RESPONSE_ALREADY_SENT\n})\n\nserve(app)\n```\n\n## Listen to a UNIX domain socket\n\nYou can configure the HTTP server to listen to a UNIX domain socket instead of a TCP port.\n\n```ts\nimport { createAdaptorServer } from '@hono/node-server'\n\n// ...\n\nconst socketPath = '/tmp/example.sock'\n\nconst server = createAdaptorServer(app)\nserver.listen(socketPath, () =\u003e {\n  console.log(`Listening on ${socketPath}`)\n})\n```\n\n## Related projects\n\n- Hono - \u003chttps://hono.dev\u003e\n- Hono GitHub repository - \u003chttps://github.com/honojs/hono\u003e\n\n## Authors\n\n- Yusuke Wada \u003chttps://github.com/yusukebe\u003e\n- Taku Amano \u003chttps://github.com/usualoma\u003e\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhonojs%2Fnode-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhonojs%2Fnode-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhonojs%2Fnode-server/lists"}