Adapters

Bun

Run your h3 apps with Bun


In order to run h3 apps in Bun, use the Web Adapter.

Alternatively you can use Node.js adapter as Bun is fully compatible with Node.js API!

Usage

Create app entry:

Create Bun server entry:

Now, your can run Bun server:

bun --bun ./server.mjs

WebSocket support

Read more in crossws.unjs.io/adapters/bun.
import wsAdapter from "crossws/adapters/bun";

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

const handler = toWebHandler(app)

const server = Bun.serve({
  port: 3000,
  websocket,
  fetch(req, server) {
    if (await handleUpgrade(req, server)) {
      return;
    }
    return handler(req)
  }
});