Skip to main content
Bun provides a fast, built-in HTTP server via Bun.serve(). It’s powered by a fork of uWebSockets and includes support for HTTP/1.1, HTTP/2, HTTPS, WebSockets, and Server-Sent Events.

Basic HTTP Server

Server Configuration

Port and Hostname

Unix Domain Sockets

Request Handling

Accessing Request Data

Route Parameters with BunRequest

Response Types

Text Response

JSON Response

File Response

Stream Response

HTTPS/TLS

Error Handling

Server Object

The Bun.serve() function returns a Server object:

Hot Reloading

Development Mode

Request IP and Timeout

Publishing to WebSockets

You can publish messages to WebSocket topics from the HTTP handler:

Reference Counting

Type Signatures