From fd8ed316cc9b344fc7256ad428327d0539b0b980 Mon Sep 17 00:00:00 2001 From: Adam Haglund Date: Wed, 31 Jan 2024 20:23:13 +0100 Subject: [PATCH] add node env bindings docs --- getting-started/nodejs.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/getting-started/nodejs.md b/getting-started/nodejs.md index 1b793d09..a136e475 100644 --- a/getting-started/nodejs.md +++ b/getting-started/nodejs.md @@ -114,6 +114,28 @@ serve({ }) ``` +## Access the raw Node.js APIs + +You can access the Node.js APIs from `c.env.incoming` and `c.env.outgoing`. + +```ts +import { Hono } from 'hono' +import { serve, type HttpBindings } from '@hono/node-server' +// or `Http2Bindings` if you use HTTP2 + +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.