Skip to content

Commit

Permalink
docs(readme): add description about Node.js API
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe committed Jan 29, 2024
1 parent a3805e6 commit 3190f81
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,40 @@ app.use(
)
```

## Accessing Node.js API

You 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.

```ts
import { serve } from '@hono/node-server'
import type { HttpBindings } from '@hono/node-server'
import { Hono } from 'hono'

const app = new Hono<{ Bindings: HttpBindings }>()

app.get('/', (c) => {
return c.json({
remoteAddress: c.env.incoming.socket.remoteAddress,
})
})

serve(app)
```

The APIs that you can get from `c.env` are as follows.

```ts
type HttpBindings = {
incoming: IncomingMessage
outgoing: ServerResponse
}

type Http2Bindings = {
incoming: Http2ServerRequest
outgoing: Http2ServerResponse
}
```
## Related projects
- Hono - <https://hono.dev>
Expand Down

0 comments on commit 3190f81

Please sign in to comment.