aboutsummaryrefslogtreecommitdiff
path: root/docs/guides/http/simple.md
blob: 53b763d586b159471cb17fa6bb53ebb869bc795f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
---
name: Write a simple HTTP server
---

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`](/docs/api/http) for details.

```ts
const server = Bun.serve({
  port: 3000,
  fetch(request) {
    return new Response("Welcome to Bun!");
  },
});

console.log(`Listening on localhost: ${server.port}`);
```
' width='13' height='13' alt='Gravatar' /> Jarred Sumner 5-1/+101 2023-02-13Add dynamic port assigning to Bun.serve (#2062)Gravatar Michał Warda 3-5/+40 2023-02-13feat(napi): add `napi_get_value_bigint_words` (#2061)Gravatar Derrick Farris 3-0/+44 2023-02-13Fixes https://github.com/oven-sh/bun/issues/1456Gravatar Jarred Sumner 8-1/+148