Adapters

Node.js

Natively run h3 servers with Node.js.


In order to start h3 apps in Node.js, use toNodeListener adapter to convert h3 app into a Node.js requestListener.

Usage

First, create an h3 app:

Create Node.js server entry:

Now, you can run you h3 app natively with Node.js:

Using listhen

Alternatively, you can use unjs/listhen. In this method, you only need to make app.mjs with a default or app export.

Run this command to run your servers:

npx --yes listhen ./app.ts

WebSocket support

Read more in crossws.unjs.io/adapters/node.
When using listhen method, websocket is supported out of the box!
import wsAdapter from "crossws/adapters/node";

const { handleUpgrade } = wsAdapter(app.websocket);

server.on("upgrade", handleUpgrade);