mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
29 lines
740 B
Plaintext
29 lines
740 B
Plaintext
---
|
|
title: Hot reload an HTTP server
|
|
sidebarTitle: Hot reload an HTTP server
|
|
mode: center
|
|
---
|
|
|
|
Bun supports the [`--hot`](/runtime/watch-mode#hot-mode) flag to run a file with hot reloading enabled. When any module or file changes, Bun re-runs the file.
|
|
|
|
```sh terminal icon="terminal"
|
|
bun --hot run index.ts
|
|
```
|
|
|
|
---
|
|
|
|
Bun detects when you are running an HTTP server with `Bun.serve()`. It reloads your fetch handler when source files change, _without_ restarting the `bun` process. This makes hot reloads nearly instantaneous.
|
|
|
|
<Note>
|
|
Note that this doesn't reload the page on your browser.
|
|
</Note>
|
|
|
|
```ts index.ts icon="/icons/typescript.svg"
|
|
Bun.serve({
|
|
port: 3000,
|
|
fetch(req) {
|
|
return new Response("Hello world");
|
|
},
|
|
});
|
|
```
|