mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
21 lines
506 B
Plaintext
21 lines
506 B
Plaintext
---
|
|
title: Write a simple HTTP server
|
|
sidebarTitle: Simple HTTP Server with Bun
|
|
mode: center
|
|
---
|
|
|
|
This starts an HTTP server listening on port `3000`. It responds to all requests with a `Response` with status `200` and body `"Welcome to Bun!"`.
|
|
|
|
See [`Bun.serve`](/runtime/http/server) for details.
|
|
|
|
```ts server.ts icon="/icons/typescript.svg"
|
|
const server = Bun.serve({
|
|
port: 3000,
|
|
fetch(request) {
|
|
return new Response("Welcome to Bun!");
|
|
},
|
|
});
|
|
|
|
console.log(`Listening on ${server.url}`);
|
|
```
|