aboutsummaryrefslogtreecommitdiff
path: root/docs/guides
diff options
context:
space:
mode:
authorGravatar Colin McDonnell <colinmcd94@gmail.com> 2023-08-21 21:34:03 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-21 21:34:03 -0700
commit3a45f2c71bb17fbad0168fa76b32ae0c8ee67935 (patch)
tree2b02a163ff489349108ad99c211e65ed77209554 /docs/guides
parent9eeb7bdbff72997709a9a4c6afb2910830d29842 (diff)
downloadbun-3a45f2c71bb17fbad0168fa76b32ae0c8ee67935.tar.gz
bun-3a45f2c71bb17fbad0168fa76b32ae0c8ee67935.tar.zst
bun-3a45f2c71bb17fbad0168fa76b32ae0c8ee67935.zip
Docs and types for v0.8.0 (#4199)
* Improve test documentation * Update nodejs compat docs with tty * Add debugger guide * Document Bun.inspect.custom, improve bun test nav * Address reviews * Update Bun.file types * Add Nuxt guide * Add tty types
Diffstat (limited to 'docs/guides')
-rw-r--r--docs/guides/ecosystem/nuxt.md65
-rw-r--r--docs/guides/runtime/web-debugger.md82
2 files changed, 147 insertions, 0 deletions
diff --git a/docs/guides/ecosystem/nuxt.md b/docs/guides/ecosystem/nuxt.md
new file mode 100644
index 000000000..bb0291754
--- /dev/null
+++ b/docs/guides/ecosystem/nuxt.md
@@ -0,0 +1,65 @@
+---
+name: Build an app with Nuxt and Bun
+---
+
+Bun supports [Nuxt](https://nuxt.com) out of the box. Initialize a Nuxt app with official `nuxi` CLI.
+
+```sh
+$ bunx nuxi init my-nuxt-app
+Nuxi 3.6.5
+✨ Nuxt project is created with v3 template. Next steps:
+ › cd my-nuxt-app
+ › Install dependencies with npm install or yarn install or pnpm install
+ › Start development server with npm run dev or yarn dev or pnpm run dev
+```
+
+---
+
+Then move into the project directory and install dependencies.
+
+```sh
+$ cd my-app
+$ bun install
+bun install v0.8.0
+ + @nuxt/devtools@0.8.0
+ + @types/node@18.17.6
+ + nuxt@3.6.5
+Nuxi 3.6.5
+✔ Types generated in .nuxt
+
+ 776 packages installed [1.72s]
+```
+
+---
+
+To start the dev server, run `bun run dev` from the project root. This will execute the `nuxt dev` command (as defined in the `"dev"` script in `package.json`).
+
+{% callout %}
+The `nuxt` CLI uses Node.js by default; passing the `--bun` flag forces the dev server to use the Bun runtime instead.
+{% /callout %}
+
+```
+$ bun --bun run dev
+ $ nuxt dev
+Nuxi 3.6.5
+Nuxt 3.6.5 with Nitro 2.5.2
+ > Local: http://localhost:3000/
+ > Network: http://192.168.0.21:3000/
+ > Network: http://[fd8a:d31d:481c:4883:1c64:3d90:9f83:d8a2]:3000/
+
+✔ Nuxt DevTools is enabled v0.8.0 (experimental)
+ℹ Vite client warmed up in 547ms
+✔ Nitro built in 244 ms
+```
+
+---
+
+Once the dev server spins up, open [http://localhost:3000](http://localhost:3000) to see the app. The app will render Nuxt's built-in `WelcomePage` template component.
+
+To start developing your app, replace `<WelcomePage />` in `app.vue` with your own UI.
+
+{% image src="https://github.com/oven-sh/bun/assets/3084745/2c683ecc-3298-4bb0-b8c0-cf4cfaea1daa" caption="Demo Nuxt app running on localhost" /%}
+
+---
+
+Refer to the [Nuxt website](https://nuxt.com/docs) for complete documentation.
diff --git a/docs/guides/runtime/web-debugger.md b/docs/guides/runtime/web-debugger.md
new file mode 100644
index 000000000..d41d93b4a
--- /dev/null
+++ b/docs/guides/runtime/web-debugger.md
@@ -0,0 +1,82 @@
+---
+name: Debugging Bun with the web debugger
+---
+
+Bun speaks the [WebKit Inspector Protocol](https://github.com/oven-sh/bun/blob/main/packages/bun-vscode/types/jsc.d.ts). To enable debugging when running code with Bun, use the `--inspect` flag. For demonstration purposes, consider the following simple web server.
+
+```ts#server.ts
+Bun.serve({
+ fetch(req){
+ console.log(req.url);
+ return new Response("Hello, world!");
+ }
+})
+```
+
+---
+
+Let's run this file with the `--inspect` flag.
+
+This automatically starts a WebSocket server on an available port that can be used to introspect the running Bun process. Various debugging tools can connect to this server to provide an interactive debugging experience.
+
+Bun hosts a web-based debugger at [debug.bun.sh](https://debug.bun.sh). It is a modified version of WebKit's [Web Inspector Interface](https://webkit.org/web-inspector/web-inspector-interface/), which will look familiar to Safari users.
+
+```sh
+$ bun --inspect server.ts
+------------------ Bun Inspector ------------------
+Listening at:
+ ws://localhost:6499/0tqxs9exrgrm
+
+Inspect in browser:
+ https://debug.bun.sh/#localhost:6499/0tqxs9exrgrm
+------------------ Bun Inspector ------------------
+```
+
+---
+
+Open the provided `debug.bun.sh` URL in your browser to start a debugging session. From this interface, you'll be able to view the source code of the running file, view and set breakpoints, and execute code with the built-in console.
+
+{% image src="https://github.com/oven-sh/bun/assets/3084745/e6a976a8-80cc-4394-8925-539025cc025d" alt="Screenshot of Bun debugger, Console tab" /%}
+
+---
+
+Let's set a breakpoint. Navigate to the Sources tab; you should see the code from earlier. Click on the line number `3` to set a breakpoint on our `console.log(req.url)` statement.
+
+{% image src="https://github.com/oven-sh/bun/assets/3084745/3b69c7e9-25ff-4f9d-acc4-caa736862935" alt="screenshot of Bun debugger" /%}
+
+---
+
+Then visit [`http://localhost:3000`](http://localhost:3000) in your web browser. This will send an HTTP request to our `localhost` web server. It will seem like the page isn't loading. Why? Because the program has paused execution at the breakpoint we set earlier.
+
+Note how the UI has changed.
+
+{% image src="https://github.com/oven-sh/bun/assets/3084745/8b565e58-5445-4061-9bc4-f41090dfe769" alt="screenshot of Bun debugger" /%}
+
+---
+
+At this point there's a lot we can do to introspect the current execution environment. We can use the console at the bottom to run arbitrary code in the context of the program, with full access to the variables in scope at our breakpoint.
+
+{% image src="https://github.com/oven-sh/bun/assets/3084745/f4312b76-48ba-4a7d-b3b6-6205968ac681" /%}
+
+---
+
+On the right side of the Sources pane, we can see all local variables currently in scope, and drill down to see their properties and methods. Here, we're inspecting the `req` variable.
+
+{% image src="https://github.com/oven-sh/bun/assets/3084745/63d7f843-5180-489c-aa94-87c486e68646" /%}
+
+---
+
+In the upper left of the Sources pane, we can control the execution of the program.
+
+{% image src="https://github.com/oven-sh/bun/assets/3084745/41b76deb-7371-4461-9d5d-81b5a6d2f7a4" /%}
+
+---
+
+Here's a cheat sheet explaining the functions of the control flow buttons.
+
+- _Continue script execution_ — continue running the program until the next breakpoint or exception.
+- _Step over_ — The program will continue to the next line.
+- _Step into_ — If the current statement contains a function call, the debugger will "step into" the called function.
+- _Step out_ — If the current statement is a function call, the debugger will finish executing the call, then "step out" of the function to the location where it was called.
+
+{% image src="https://github-production-user-asset-6210df.s3.amazonaws.com/3084745/261510346-6a94441c-75d3-413a-99a7-efa62365f83d.png" /%}