diff options
-rw-r--r-- | docs/api/http.md | 4 | ||||
-rw-r--r-- | docs/api/utils.md | 26 | ||||
-rw-r--r-- | docs/runtime/hot.md | 4 |
3 files changed, 32 insertions, 2 deletions
diff --git a/docs/api/http.md b/docs/api/http.md index 4cb55349a..3e11299dd 100644 --- a/docs/api/http.md +++ b/docs/api/http.md @@ -134,11 +134,13 @@ Bun.serve({ Thus far, the examples on this page have used the explicit `Bun.serve` API. Bun also supports an alternate syntax. ```ts#server.ts +import {type Serve} from "bun"; + export default { fetch(req) { return new Response(`Bun!`); }, -}; +} satisfies Serve; ``` Instead of passing the server options into `Bun.serve`, export it. This file can be executed as-is; when Bun runs a file with a `default` export containing a `fetch` handler, it passes it into `Bun.serve` under the hood. diff --git a/docs/api/utils.md b/docs/api/utils.md index dcd9c0128..ce3d0d6f9 100644 --- a/docs/api/utils.md +++ b/docs/api/utils.md @@ -118,3 +118,29 @@ test("peek.status", () => { expect(peek.status(rejected)).toBe("rejected"); }); ``` + +## `Bun.openInEditor` + +Open a file in your default editor. Bun auto-detects your editor via the `$VISUAL` or `$EDITOR` environment variables. + +```ts +const currentFile = import.meta.url; +Bun.openInEditor(currentFile); +``` + +You can override this via the `debug.editor` setting in your [`bunfig.toml`](/docs/project/configuration) + +```toml-diff#bunfig.toml ++ [debug] ++ editor = "code" +``` + +Or specify an editor with the `editor` param. You can also specify a line and column number. + +```ts +Bun.openInEditor(import.meta.url, { + editor: "vscode", // or "subl" + line: 10, + column: 5, +}) +``` diff --git a/docs/runtime/hot.md b/docs/runtime/hot.md index 96571453c..a66534949 100644 --- a/docs/runtime/hot.md +++ b/docs/runtime/hot.md @@ -39,6 +39,8 @@ Traditional file watchers like `nodemon` restart the entire process, so HTTP ser Bun provides the following simplified API for implementing HTTP servers. Refer to [API > HTTP](/docs/api/http) for full details. ```ts#server.ts +import {type Serve} from "bun"; + globalThis.count = globalThis.count ?? 0; globalThis.count++; @@ -47,7 +49,7 @@ export default { return new Response(`Reloaded ${globalThis.count} times`); }, port: 3000, -}; +} satisfies Serve; ``` The file above is simply exporting an object with a `fetch` handler defined. When this file is executed, Bun interprets this as an HTTP server and passes the exported object into `Bun.serve`. |