bun-types 1.3.2-canary.20251106T140813 → 1.3.2-canary.20251108T140624

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (316) hide show
  1. package/bun.d.ts +102 -6
  2. package/docs/bundler/bytecode.mdx +465 -0
  3. package/docs/bundler/css.mdx +1024 -0
  4. package/docs/bundler/esbuild.mdx +253 -0
  5. package/docs/bundler/executables.mdx +535 -0
  6. package/docs/bundler/fullstack.mdx +1064 -0
  7. package/docs/bundler/hot-reloading.mdx +229 -0
  8. package/docs/bundler/html-static.mdx +386 -0
  9. package/docs/bundler/index.mdx +1499 -0
  10. package/docs/bundler/loaders.mdx +356 -0
  11. package/docs/bundler/macros.mdx +328 -0
  12. package/docs/bundler/minifier.mdx +1306 -0
  13. package/docs/bundler/plugins.mdx +411 -0
  14. package/docs/feedback.mdx +85 -0
  15. package/docs/guides/binary/arraybuffer-to-array.mdx +29 -0
  16. package/docs/guides/binary/arraybuffer-to-blob.mdx +26 -0
  17. package/docs/guides/binary/arraybuffer-to-buffer.mdx +27 -0
  18. package/docs/guides/binary/arraybuffer-to-string.mdx +17 -0
  19. package/docs/guides/binary/arraybuffer-to-typedarray.mdx +41 -0
  20. package/docs/guides/binary/blob-to-arraybuffer.mdx +16 -0
  21. package/docs/guides/binary/blob-to-dataview.mdx +16 -0
  22. package/docs/guides/binary/blob-to-stream.mdx +16 -0
  23. package/docs/guides/binary/blob-to-string.mdx +17 -0
  24. package/docs/guides/binary/blob-to-typedarray.mdx +16 -0
  25. package/docs/guides/binary/buffer-to-arraybuffer.mdx +16 -0
  26. package/docs/guides/binary/buffer-to-blob.mdx +16 -0
  27. package/docs/guides/binary/buffer-to-readablestream.mdx +43 -0
  28. package/docs/guides/binary/buffer-to-string.mdx +27 -0
  29. package/docs/guides/binary/buffer-to-typedarray.mdx +16 -0
  30. package/docs/guides/binary/dataview-to-string.mdx +17 -0
  31. package/docs/guides/binary/typedarray-to-arraybuffer.mdx +27 -0
  32. package/docs/guides/binary/typedarray-to-blob.mdx +18 -0
  33. package/docs/guides/binary/typedarray-to-buffer.mdx +16 -0
  34. package/docs/guides/binary/typedarray-to-dataview.mdx +16 -0
  35. package/docs/guides/binary/typedarray-to-readablestream.mdx +43 -0
  36. package/docs/guides/binary/typedarray-to-string.mdx +18 -0
  37. package/docs/guides/deployment/aws-lambda.mdx +204 -0
  38. package/docs/guides/deployment/digital-ocean.mdx +161 -0
  39. package/docs/guides/deployment/google-cloud-run.mdx +197 -0
  40. package/docs/guides/deployment/railway.mdx +145 -0
  41. package/docs/guides/deployment/render.mdx +82 -0
  42. package/docs/guides/deployment/vercel.mdx +99 -0
  43. package/docs/guides/ecosystem/astro.mdx +82 -0
  44. package/docs/guides/ecosystem/discordjs.mdx +80 -0
  45. package/docs/guides/ecosystem/docker.mdx +151 -0
  46. package/docs/guides/ecosystem/drizzle.mdx +195 -0
  47. package/docs/guides/ecosystem/edgedb.mdx +257 -0
  48. package/docs/guides/ecosystem/elysia.mdx +31 -0
  49. package/docs/guides/ecosystem/express.mdx +43 -0
  50. package/docs/guides/ecosystem/hono.mdx +47 -0
  51. package/docs/guides/ecosystem/mongoose.mdx +92 -0
  52. package/docs/guides/ecosystem/neon-drizzle.mdx +234 -0
  53. package/docs/guides/ecosystem/neon-serverless-postgres.mdx +60 -0
  54. package/docs/guides/ecosystem/nextjs.mdx +57 -0
  55. package/docs/guides/ecosystem/nuxt.mdx +90 -0
  56. package/docs/guides/ecosystem/pm2.mdx +55 -0
  57. package/docs/guides/ecosystem/prisma-postgres.mdx +169 -0
  58. package/docs/guides/ecosystem/prisma.mdx +164 -0
  59. package/docs/guides/ecosystem/qwik.mdx +114 -0
  60. package/docs/guides/ecosystem/react.mdx +52 -0
  61. package/docs/guides/ecosystem/remix.mdx +97 -0
  62. package/docs/guides/ecosystem/sentry.mdx +54 -0
  63. package/docs/guides/ecosystem/solidstart.mdx +66 -0
  64. package/docs/guides/ecosystem/ssr-react.mdx +49 -0
  65. package/docs/guides/ecosystem/stric.mdx +54 -0
  66. package/docs/guides/ecosystem/sveltekit.mdx +138 -0
  67. package/docs/guides/ecosystem/systemd.mdx +114 -0
  68. package/docs/guides/ecosystem/upstash.mdx +87 -0
  69. package/docs/guides/ecosystem/vite.mdx +77 -0
  70. package/docs/guides/html-rewriter/extract-links.mdx +72 -0
  71. package/docs/guides/html-rewriter/extract-social-meta.mdx +97 -0
  72. package/docs/guides/http/cluster.mdx +69 -0
  73. package/docs/guides/http/fetch-unix.mdx +35 -0
  74. package/docs/guides/http/fetch.mdx +26 -0
  75. package/docs/guides/http/file-uploads.mdx +97 -0
  76. package/docs/guides/http/hot.mdx +28 -0
  77. package/docs/guides/http/proxy.mdx +26 -0
  78. package/docs/guides/http/server.mdx +48 -0
  79. package/docs/guides/http/simple.mdx +20 -0
  80. package/docs/guides/http/stream-file.mdx +50 -0
  81. package/docs/guides/http/stream-iterator.mdx +49 -0
  82. package/docs/guides/http/stream-node-streams-in-bun.mdx +22 -0
  83. package/docs/guides/http/tls.mdx +32 -0
  84. package/docs/guides/index.mdx +10 -0
  85. package/docs/guides/install/add-dev.mdx +28 -0
  86. package/docs/guides/install/add-git.mdx +38 -0
  87. package/docs/guides/install/add-optional.mdx +27 -0
  88. package/docs/guides/install/add-peer.mdx +45 -0
  89. package/docs/guides/install/add-tarball.mdx +35 -0
  90. package/docs/guides/install/add.mdx +44 -0
  91. package/docs/guides/install/azure-artifacts.mdx +76 -0
  92. package/docs/guides/install/cicd.mdx +43 -0
  93. package/docs/guides/install/custom-registry.mdx +32 -0
  94. package/docs/guides/install/from-npm-install-to-bun-install.mdx +230 -0
  95. package/docs/guides/install/git-diff-bun-lockfile.mdx +47 -0
  96. package/docs/guides/install/jfrog-artifactory.mdx +28 -0
  97. package/docs/guides/install/npm-alias.mdx +25 -0
  98. package/docs/guides/install/registry-scope.mdx +40 -0
  99. package/docs/guides/install/trusted.mdx +50 -0
  100. package/docs/guides/install/workspaces.mdx +70 -0
  101. package/docs/guides/install/yarnlock.mdx +50 -0
  102. package/docs/guides/process/argv.mdx +66 -0
  103. package/docs/guides/process/ctrl-c.mdx +18 -0
  104. package/docs/guides/process/ipc.mdx +69 -0
  105. package/docs/guides/process/nanoseconds.mdx +15 -0
  106. package/docs/guides/process/os-signals.mdx +41 -0
  107. package/docs/guides/process/spawn-stderr.mdx +34 -0
  108. package/docs/guides/process/spawn-stdout.mdx +28 -0
  109. package/docs/guides/process/spawn.mdx +43 -0
  110. package/docs/guides/process/stdin.mdx +62 -0
  111. package/docs/guides/read-file/arraybuffer.mdx +30 -0
  112. package/docs/guides/read-file/buffer.mdx +21 -0
  113. package/docs/guides/read-file/exists.mdx +18 -0
  114. package/docs/guides/read-file/json.mdx +19 -0
  115. package/docs/guides/read-file/mime.mdx +22 -0
  116. package/docs/guides/read-file/stream.mdx +28 -0
  117. package/docs/guides/read-file/string.mdx +24 -0
  118. package/docs/guides/read-file/uint8array.mdx +23 -0
  119. package/docs/guides/read-file/watch.mdx +66 -0
  120. package/docs/guides/runtime/build-time-constants.mdx +295 -0
  121. package/docs/guides/runtime/cicd.mdx +45 -0
  122. package/docs/guides/runtime/codesign-macos-executable.mdx +61 -0
  123. package/docs/guides/runtime/define-constant.mdx +149 -0
  124. package/docs/guides/runtime/delete-directory.mdx +39 -0
  125. package/docs/guides/runtime/delete-file.mdx +21 -0
  126. package/docs/guides/runtime/heap-snapshot.mdx +28 -0
  127. package/docs/guides/runtime/import-html.mdx +17 -0
  128. package/docs/guides/runtime/import-json.mdx +46 -0
  129. package/docs/guides/runtime/import-toml.mdx +32 -0
  130. package/docs/guides/runtime/import-yaml.mdx +104 -0
  131. package/docs/guides/runtime/read-env.mdx +37 -0
  132. package/docs/guides/runtime/set-env.mdx +51 -0
  133. package/docs/guides/runtime/shell.mdx +42 -0
  134. package/docs/guides/runtime/timezone.mdx +38 -0
  135. package/docs/guides/runtime/tsconfig-paths.mdx +31 -0
  136. package/docs/guides/runtime/typescript.mdx +51 -0
  137. package/docs/guides/runtime/vscode-debugger.mdx +48 -0
  138. package/docs/guides/runtime/web-debugger.mdx +103 -0
  139. package/docs/guides/streams/node-readable-to-arraybuffer.mdx +13 -0
  140. package/docs/guides/streams/node-readable-to-blob.mdx +13 -0
  141. package/docs/guides/streams/node-readable-to-json.mdx +14 -0
  142. package/docs/guides/streams/node-readable-to-string.mdx +14 -0
  143. package/docs/guides/streams/node-readable-to-uint8array.mdx +13 -0
  144. package/docs/guides/streams/to-array.mdx +16 -0
  145. package/docs/guides/streams/to-arraybuffer.mdx +16 -0
  146. package/docs/guides/streams/to-blob.mdx +16 -0
  147. package/docs/guides/streams/to-buffer.mdx +17 -0
  148. package/docs/guides/streams/to-json.mdx +16 -0
  149. package/docs/guides/streams/to-string.mdx +16 -0
  150. package/docs/guides/streams/to-typedarray.mdx +24 -0
  151. package/docs/guides/test/bail.mdx +24 -0
  152. package/docs/guides/test/coverage-threshold.mdx +67 -0
  153. package/docs/guides/test/coverage.mdx +49 -0
  154. package/docs/guides/test/happy-dom.mdx +73 -0
  155. package/docs/guides/test/migrate-from-jest.mdx +125 -0
  156. package/docs/guides/test/mock-clock.mdx +50 -0
  157. package/docs/guides/test/mock-functions.mdx +70 -0
  158. package/docs/guides/test/rerun-each.mdx +16 -0
  159. package/docs/guides/test/run-tests.mdx +116 -0
  160. package/docs/guides/test/skip-tests.mdx +43 -0
  161. package/docs/guides/test/snapshot.mdx +102 -0
  162. package/docs/guides/test/spy-on.mdx +49 -0
  163. package/docs/guides/test/svelte-test.mdx +113 -0
  164. package/docs/guides/test/testing-library.mdx +93 -0
  165. package/docs/guides/test/timeout.mdx +17 -0
  166. package/docs/guides/test/todo-tests.mdx +74 -0
  167. package/docs/guides/test/update-snapshots.mdx +49 -0
  168. package/docs/guides/test/watch-mode.mdx +24 -0
  169. package/docs/guides/util/base64.mdx +17 -0
  170. package/docs/guides/util/deep-equals.mdx +41 -0
  171. package/docs/guides/util/deflate.mdx +20 -0
  172. package/docs/guides/util/detect-bun.mdx +25 -0
  173. package/docs/guides/util/entrypoint.mdx +19 -0
  174. package/docs/guides/util/escape-html.mdx +24 -0
  175. package/docs/guides/util/file-url-to-path.mdx +16 -0
  176. package/docs/guides/util/gzip.mdx +20 -0
  177. package/docs/guides/util/hash-a-password.mdx +56 -0
  178. package/docs/guides/util/import-meta-dir.mdx +15 -0
  179. package/docs/guides/util/import-meta-file.mdx +15 -0
  180. package/docs/guides/util/import-meta-path.mdx +15 -0
  181. package/docs/guides/util/javascript-uuid.mdx +25 -0
  182. package/docs/guides/util/main.mdx +43 -0
  183. package/docs/guides/util/path-to-file-url.mdx +16 -0
  184. package/docs/guides/util/sleep.mdx +24 -0
  185. package/docs/guides/util/version.mdx +23 -0
  186. package/docs/guides/util/which-path-to-executable-bin.mdx +17 -0
  187. package/docs/guides/websocket/compression.mdx +33 -0
  188. package/docs/guides/websocket/context.mdx +74 -0
  189. package/docs/guides/websocket/pubsub.mdx +40 -0
  190. package/docs/guides/websocket/simple.mdx +35 -0
  191. package/docs/guides/write-file/append.mdx +54 -0
  192. package/docs/guides/write-file/basic.mdx +46 -0
  193. package/docs/guides/write-file/blob.mdx +30 -0
  194. package/docs/guides/write-file/cat.mdx +19 -0
  195. package/docs/guides/write-file/file-cp.mdx +18 -0
  196. package/docs/guides/write-file/filesink.mdx +54 -0
  197. package/docs/guides/write-file/response.mdx +19 -0
  198. package/docs/guides/write-file/stdout.mdx +23 -0
  199. package/docs/guides/write-file/stream.mdx +19 -0
  200. package/docs/guides/write-file/unlink.mdx +18 -0
  201. package/docs/index.mdx +133 -0
  202. package/docs/installation.mdx +365 -0
  203. package/docs/pm/bunx.mdx +83 -0
  204. package/docs/pm/catalogs.mdx +292 -0
  205. package/docs/pm/cli/add.mdx +179 -0
  206. package/docs/pm/cli/audit.mdx +60 -0
  207. package/docs/pm/cli/install.mdx +471 -0
  208. package/docs/pm/cli/link.mdx +48 -0
  209. package/docs/pm/cli/outdated.mdx +197 -0
  210. package/docs/pm/cli/patch.mdx +69 -0
  211. package/docs/pm/cli/pm.mdx +319 -0
  212. package/docs/pm/cli/publish.mdx +123 -0
  213. package/docs/pm/cli/remove.mdx +16 -0
  214. package/docs/pm/cli/update.mdx +140 -0
  215. package/docs/pm/cli/why.mdx +84 -0
  216. package/docs/pm/filter.mdx +102 -0
  217. package/docs/pm/global-cache.mdx +72 -0
  218. package/docs/pm/isolated-installs.mdx +205 -0
  219. package/docs/pm/lifecycle.mdx +57 -0
  220. package/docs/pm/lockfile.mdx +64 -0
  221. package/docs/pm/npmrc.mdx +111 -0
  222. package/docs/pm/overrides.mdx +83 -0
  223. package/docs/pm/scopes-registries.mdx +35 -0
  224. package/docs/pm/security-scanner-api.mdx +95 -0
  225. package/docs/pm/workspaces.mdx +109 -0
  226. package/docs/project/benchmarking.mdx +218 -0
  227. package/docs/project/bindgen.mdx +223 -0
  228. package/docs/project/building-windows.mdx +133 -0
  229. package/docs/project/contributing.mdx +343 -0
  230. package/docs/project/feedback.mdx +20 -0
  231. package/docs/project/license.mdx +78 -0
  232. package/docs/project/roadmap.mdx +8 -0
  233. package/docs/quickstart.mdx +240 -0
  234. package/docs/runtime/auto-install.mdx +97 -0
  235. package/docs/runtime/binary-data.mdx +846 -0
  236. package/docs/runtime/bun-apis.mdx +59 -0
  237. package/docs/runtime/bunfig.mdx +642 -0
  238. package/docs/runtime/c-compiler.mdx +204 -0
  239. package/docs/runtime/child-process.mdx +532 -0
  240. package/docs/runtime/color.mdx +267 -0
  241. package/docs/runtime/console.mdx +67 -0
  242. package/docs/runtime/cookies.mdx +454 -0
  243. package/docs/runtime/debugger.mdx +335 -0
  244. package/docs/runtime/environment-variables.mdx +214 -0
  245. package/docs/runtime/ffi.mdx +565 -0
  246. package/docs/runtime/file-io.mdx +306 -0
  247. package/docs/runtime/file-system-router.mdx +118 -0
  248. package/docs/runtime/file-types.mdx +354 -0
  249. package/docs/runtime/glob.mdx +181 -0
  250. package/docs/runtime/globals.mdx +72 -0
  251. package/docs/runtime/hashing.mdx +315 -0
  252. package/docs/runtime/html-rewriter.mdx +340 -0
  253. package/docs/runtime/http/cookies.mdx +79 -0
  254. package/docs/runtime/http/error-handling.mdx +40 -0
  255. package/docs/runtime/http/metrics.mdx +36 -0
  256. package/docs/runtime/http/routing.mdx +289 -0
  257. package/docs/runtime/http/server.mdx +647 -0
  258. package/docs/runtime/http/tls.mdx +101 -0
  259. package/docs/runtime/http/websockets.mdx +404 -0
  260. package/docs/runtime/index.mdx +223 -0
  261. package/docs/runtime/jsx.mdx +115 -0
  262. package/docs/runtime/module-resolution.mdx +342 -0
  263. package/docs/runtime/networking/dns.mdx +111 -0
  264. package/docs/runtime/networking/fetch.mdx +468 -0
  265. package/docs/runtime/networking/tcp.mdx +239 -0
  266. package/docs/runtime/networking/udp.mdx +129 -0
  267. package/docs/runtime/node-api.mdx +19 -0
  268. package/docs/runtime/nodejs-compat.mdx +468 -0
  269. package/docs/runtime/plugins.mdx +405 -0
  270. package/docs/runtime/redis.mdx +582 -0
  271. package/docs/runtime/s3.mdx +863 -0
  272. package/docs/runtime/secrets.mdx +336 -0
  273. package/docs/runtime/semver.mdx +57 -0
  274. package/docs/runtime/shell.mdx +637 -0
  275. package/docs/runtime/sql.mdx +1404 -0
  276. package/docs/runtime/sqlite.mdx +699 -0
  277. package/docs/runtime/streams.mdx +232 -0
  278. package/docs/runtime/templating/create.mdx +269 -0
  279. package/docs/runtime/templating/init.mdx +58 -0
  280. package/docs/runtime/transpiler.mdx +288 -0
  281. package/docs/runtime/typescript.mdx +58 -0
  282. package/docs/runtime/utils.mdx +922 -0
  283. package/docs/runtime/watch-mode.mdx +161 -0
  284. package/docs/runtime/web-apis.mdx +29 -0
  285. package/docs/runtime/workers.mdx +328 -0
  286. package/docs/runtime/yaml.mdx +469 -0
  287. package/docs/snippets/cli/add.mdx +166 -0
  288. package/docs/snippets/cli/build.mdx +196 -0
  289. package/docs/snippets/cli/feedback.mdx +17 -0
  290. package/docs/snippets/cli/init.mdx +84 -0
  291. package/docs/snippets/cli/install.mdx +173 -0
  292. package/docs/snippets/cli/link.mdx +163 -0
  293. package/docs/snippets/cli/outdated.mdx +140 -0
  294. package/docs/snippets/cli/patch.mdx +171 -0
  295. package/docs/snippets/cli/publish.mdx +198 -0
  296. package/docs/snippets/cli/remove.mdx +146 -0
  297. package/docs/snippets/cli/run.mdx +293 -0
  298. package/docs/snippets/cli/test.mdx +100 -0
  299. package/docs/snippets/cli/update.mdx +144 -0
  300. package/docs/snippets/product-card.mdx +32 -0
  301. package/docs/snippets/product-tiles.mdx +94 -0
  302. package/docs/test/code-coverage.mdx +409 -0
  303. package/docs/test/configuration.mdx +467 -0
  304. package/docs/test/dates-times.mdx +129 -0
  305. package/docs/test/discovery.mdx +90 -0
  306. package/docs/test/dom.mdx +226 -0
  307. package/docs/test/index.mdx +380 -0
  308. package/docs/test/lifecycle.mdx +348 -0
  309. package/docs/test/mocks.mdx +637 -0
  310. package/docs/test/reporters.mdx +117 -0
  311. package/docs/test/runtime-behavior.mdx +342 -0
  312. package/docs/test/snapshots.mdx +434 -0
  313. package/docs/test/writing-tests.mdx +635 -0
  314. package/docs/typescript.mdx +54 -0
  315. package/package.json +8 -6
  316. package/test.d.ts +2 -2
@@ -0,0 +1,335 @@
1
+ ---
2
+ title: "Debugging"
3
+ description: "Debug your Bun code with an interactive debugger using WebKit Inspector Protocol"
4
+ ---
5
+
6
+ Bun speaks the [WebKit Inspector Protocol](https://github.com/oven-sh/bun/blob/main/packages/bun-inspector-protocol/src/protocol/jsc/index.d.ts), so you can debug your code with an interactive debugger. For demonstration purposes, consider the following simple web server.
7
+
8
+ ## Debugging JavaScript and TypeScript
9
+
10
+ ```typescript icon="/icons/typescript.svg" title="server.ts"
11
+ Bun.serve({
12
+ fetch(req) {
13
+ console.log(req.url);
14
+ return new Response("Hello, world!");
15
+ },
16
+ });
17
+ ```
18
+
19
+ ### `--inspect`
20
+
21
+ To enable debugging when running code with Bun, use the `--inspect` flag. This automatically starts a WebSocket server on an available port that can be used to introspect the running Bun process.
22
+
23
+ ```sh icon="terminal" title="terminal"
24
+ bun --inspect server.ts
25
+ ```
26
+
27
+ ```txt id="terminal"
28
+ ------------------ Bun Inspector ------------------
29
+ Listening at:
30
+ ws://localhost:6499/0tqxs9exrgrm
31
+
32
+ Inspect in browser:
33
+ https://debug.bun.sh/#localhost:6499/0tqxs9exrgrm
34
+ ------------------ Bun Inspector ------------------
35
+ ```
36
+
37
+ ### `--inspect-brk`
38
+
39
+ The `--inspect-brk` flag behaves identically to `--inspect`, except it automatically injects a breakpoint at the first line of the executed script. This is useful for debugging scripts that run quickly and exit immediately.
40
+
41
+ ### `--inspect-wait`
42
+
43
+ The `--inspect-wait` flag behaves identically to `--inspect`, except the code will not execute until a debugger has attached to the running process.
44
+
45
+ ### Setting a port or URL for the debugger
46
+
47
+ Regardless of which flag you use, you can optionally specify a port number, URL prefix, or both.
48
+
49
+ ```sh icon="terminal" title="terminal"
50
+ bun --inspect=4000 server.ts
51
+ bun --inspect=localhost:4000 server.ts
52
+ bun --inspect=localhost:4000/prefix server.ts
53
+ ```
54
+
55
+ ---
56
+
57
+ ## Debuggers
58
+
59
+ Various debugging tools can connect to this server to provide an interactive debugging experience.
60
+
61
+ ### `debug.bun.sh`
62
+
63
+ 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.
64
+
65
+ 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.
66
+
67
+ <Frame>
68
+ ![Screenshot of Bun debugger, Console
69
+ tab](https://github.com/oven-sh/bun/assets/3084745/e6a976a8-80cc-4394-8925-539025cc025d)
70
+ </Frame>
71
+
72
+ 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.
73
+
74
+ <Frame>
75
+ ![screenshot of Bun debugger](https://github.com/oven-sh/bun/assets/3084745/3b69c7e9-25ff-4f9d-acc4-caa736862935)
76
+ </Frame>
77
+
78
+ 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.
79
+
80
+ Note how the UI has changed.
81
+
82
+ <Frame>
83
+ ![screenshot of Bun debugger](https://github.com/oven-sh/bun/assets/3084745/8b565e58-5445-4061-9bc4-f41090dfe769)
84
+ </Frame>
85
+
86
+ 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.
87
+
88
+ <Frame>
89
+ ![Bun debugger console](https://github.com/oven-sh/bun/assets/3084745/f4312b76-48ba-4a7d-b3b6-6205968ac681)
90
+ </Frame>
91
+
92
+ 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.
93
+
94
+ <Frame>
95
+ ![Bun debugger variables](https://github.com/oven-sh/bun/assets/3084745/63d7f843-5180-489c-aa94-87c486e68646)
96
+ </Frame>
97
+
98
+ In the upper left of the Sources pane, we can control the execution of the program.
99
+
100
+ <Frame>
101
+ ![Bun debugger controls](https://github.com/oven-sh/bun/assets/3084745/41b76deb-7371-4461-9d5d-81b5a6d2f7a4)
102
+ </Frame>
103
+
104
+ Here's a cheat sheet explaining the functions of the control flow buttons.
105
+
106
+ - _Continue script execution_ — continue running the program until the next breakpoint or exception.
107
+ - _Step over_ — The program will continue to the next line.
108
+ - _Step into_ — If the current statement contains a function call, the debugger will "step into" the called function.
109
+ - _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.
110
+
111
+ <Frame>
112
+ ![Bun debugger execution
113
+ controls](https://github-production-user-asset-6210df.s3.amazonaws.com/3084745/261510346-6a94441c-75d3-413a-99a7-efa62365f83d.png)
114
+ </Frame>
115
+
116
+ ### Visual Studio Code Debugger
117
+
118
+ Experimental support for debugging Bun scripts is available in Visual Studio Code. To use it, you'll need to install the [Bun VSCode extension](https://bun.com/guides/runtime/vscode-debugger).
119
+
120
+ ---
121
+
122
+ ## Debugging Network Requests
123
+
124
+ The `BUN_CONFIG_VERBOSE_FETCH` environment variable lets you log network requests made with `fetch()` or `node:http` automatically.
125
+
126
+ | Value | Description |
127
+ | ------- | ---------------------------------- |
128
+ | `curl` | Print requests as `curl` commands. |
129
+ | `true` | Print request & response info |
130
+ | `false` | Don't print anything. Default |
131
+
132
+ ### Print fetch & node:http requests as curl commands
133
+
134
+ Bun also supports printing `fetch()` and `node:http` network requests as `curl` commands by setting the environment variable `BUN_CONFIG_VERBOSE_FETCH` to `curl`. This prints the `fetch` request as a single-line `curl` command to let you copy-paste into your terminal to replicate the request.
135
+
136
+ ```ts index.ts icon="/icons/typescript.svg"
137
+ process.env.BUN_CONFIG_VERBOSE_FETCH = "curl";
138
+
139
+ await fetch("https://example.com", {
140
+ method: "POST",
141
+ headers: {
142
+ "Content-Type": "application/json",
143
+ },
144
+ body: JSON.stringify({ foo: "bar" }),
145
+ });
146
+ ```
147
+
148
+ ```txt
149
+ [fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.3.1" -H "Accept: */*" -H "Host: example.com" -H "Accept-Encoding: gzip, deflate, br" --compressed -H "Content-Length: 13" --data-raw "{\"foo\":\"bar\"}"
150
+ [fetch] > HTTP/1.1 POST https://example.com/
151
+ [fetch] > content-type: application/json
152
+ [fetch] > Connection: keep-alive
153
+ [fetch] > User-Agent: Bun/1.3.1
154
+ [fetch] > Accept: */*
155
+ [fetch] > Host: example.com
156
+ [fetch] > Accept-Encoding: gzip, deflate, br
157
+ [fetch] > Content-Length: 13
158
+
159
+ [fetch] < 200 OK
160
+ [fetch] < Accept-Ranges: bytes
161
+ [fetch] < Cache-Control: max-age=604800
162
+ [fetch] < Content-Type: text/html; charset=UTF-8
163
+ [fetch] < Date: Tue, 18 Jun 2024 05:12:07 GMT
164
+ [fetch] < Etag: "3147526947"
165
+ [fetch] < Expires: Tue, 25 Jun 2024 05:12:07 GMT
166
+ [fetch] < Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
167
+ [fetch] < Server: EOS (vny/044F)
168
+ [fetch] < Content-Length: 1256
169
+ ```
170
+
171
+ The lines with `[fetch] >` are the request from your local code, and the lines with `[fetch] <` are the response from the remote server.
172
+
173
+ The `BUN_CONFIG_VERBOSE_FETCH` environment variable is supported in both `fetch()` and `node:http` requests, so it should just work.
174
+
175
+ To print without the `curl` command, set `BUN_CONFIG_VERBOSE_FETCH` to `true`.
176
+
177
+ ```ts index.ts icon="/icons/typescript.svg"
178
+ process.env.BUN_CONFIG_VERBOSE_FETCH = "true";
179
+
180
+ await fetch("https://example.com", {
181
+ method: "POST",
182
+ headers: {
183
+ "Content-Type": "application/json",
184
+ },
185
+ body: JSON.stringify({ foo: "bar" }),
186
+ });
187
+ ```
188
+
189
+ ```txt
190
+ [fetch] > HTTP/1.1 POST https://example.com/
191
+ [fetch] > content-type: application/json
192
+ [fetch] > Connection: keep-alive
193
+ [fetch] > User-Agent: Bun/1.3.1
194
+ [fetch] > Accept: */*
195
+ [fetch] > Host: example.com
196
+ [fetch] > Accept-Encoding: gzip, deflate, br
197
+ [fetch] > Content-Length: 13
198
+
199
+ [fetch] < 200 OK
200
+ [fetch] < Accept-Ranges: bytes
201
+ [fetch] < Cache-Control: max-age=604800
202
+ [fetch] < Content-Type: text/html; charset=UTF-8
203
+ [fetch] < Date: Tue, 18 Jun 2024 05:12:07 GMT
204
+ [fetch] < Etag: "3147526947"
205
+ [fetch] < Expires: Tue, 25 Jun 2024 05:12:07 GMT
206
+ [fetch] < Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
207
+ [fetch] < Server: EOS (vny/044F)
208
+ [fetch] < Content-Length: 1256
209
+ ```
210
+
211
+ ---
212
+
213
+ ## Stacktraces & sourcemaps
214
+
215
+ Bun transpiles every file, which sounds like it would mean that the stack traces you see in the console would unhelpfully point to the transpiled output. To address this, Bun automatically generates and serves sourcemapped files for every file it transpiles. When you see a stack trace in the console, you can click on the file path and be taken to the original source code, even though it was written in TypeScript or JSX, or has some other transformation applied.
216
+
217
+ Bun automatically loads sourcemaps both at runtime when transpiling files on-demand, and when using `bun build` to precompile files ahead of time.
218
+
219
+ ### Syntax-highlighted source code preview
220
+
221
+ To help with debugging, Bun automatically prints a small source-code preview when an unhandled exception or rejection occurs. You can simulate this behavior by calling `Bun.inspect(error)`:
222
+
223
+ ```ts
224
+ // Create an error
225
+ const err = new Error("Something went wrong");
226
+ console.log(Bun.inspect(err, { colors: true }));
227
+ ```
228
+
229
+ This prints a syntax-highlighted preview of the source code where the error occurred, along with the error message and stack trace.
230
+
231
+ ```ts icon="file-code"
232
+ 1 | // Create an error
233
+ 2 | const err = new Error("Something went wrong");
234
+ ^
235
+ error: Something went wrong
236
+ at file.js:2:13
237
+ ```
238
+
239
+ ### V8 Stack Traces
240
+
241
+ Bun uses JavaScriptCore as it's engine, but much of the Node.js ecosystem & npm expects V8. JavaScript engines differ in `error.stack` formatting. Bun intends to be a drop-in replacement for Node.js, and that means it's our job to make sure that even though the engine is different, the stack traces are as similar as possible.
242
+
243
+ That's why when you log `error.stack` in Bun, the formatting of `error.stack` is the same as in Node.js's V8 engine. This is especially useful when you're using libraries that expect V8 stack traces.
244
+
245
+ #### V8 Stack Trace API
246
+
247
+ Bun implements the [V8 Stack Trace API](https://v8.dev/docs/stack-trace-api), which is a set of functions that allow you to manipulate stack traces.
248
+
249
+ ##### `Error.prepareStackTrace`
250
+
251
+ The `Error.prepareStackTrace` function is a global function that lets you customize the stack trace output. This function is called with the error object and an array of `CallSite` objects and lets you return a custom stack trace.
252
+
253
+ ```ts
254
+ Error.prepareStackTrace = (err, stack) => {
255
+ return stack.map(callSite => {
256
+ return callSite.getFileName();
257
+ });
258
+ };
259
+
260
+ const err = new Error("Something went wrong");
261
+ console.log(err.stack);
262
+ // [ "error.js" ]
263
+ ```
264
+
265
+ The `CallSite` object has the following methods:
266
+
267
+ | Method | Returns |
268
+ | -------------------------- | ----------------------------------------------------- |
269
+ | `getThis` | `this` value of the function call |
270
+ | `getTypeName` | typeof `this` |
271
+ | `getFunction` | function object |
272
+ | `getFunctionName` | function name as a string |
273
+ | `getMethodName` | method name as a string |
274
+ | `getFileName` | file name or URL |
275
+ | `getLineNumber` | line number |
276
+ | `getColumnNumber` | column number |
277
+ | `getEvalOrigin` | `undefined` |
278
+ | `getScriptNameOrSourceURL` | source URL |
279
+ | `isToplevel` | returns `true` if the function is in the global scope |
280
+ | `isEval` | returns `true` if the function is an `eval` call |
281
+ | `isNative` | returns `true` if the function is native |
282
+ | `isConstructor` | returns `true` if the function is a constructor |
283
+ | `isAsync` | returns `true` if the function is `async` |
284
+ | `isPromiseAll` | Not implemented yet. |
285
+ | `getPromiseIndex` | Not implemented yet. |
286
+ | `toString` | returns a string representation of the call site |
287
+
288
+ In some cases, the `Function` object may have already been garbage collected, so some of these methods may return `undefined`.
289
+
290
+ ##### `Error.captureStackTrace(error, startFn)`
291
+
292
+ The `Error.captureStackTrace` function lets you capture a stack trace at a specific point in your code, rather than at the point where the error was thrown.
293
+
294
+ This can be helpful when you have callbacks or asynchronous code that makes it difficult to determine where an error originated. The 2nd argument to `Error.captureStackTrace` is the function where you want the stack trace to start.
295
+
296
+ For example, the below code will make `err.stack` point to the code calling `fn()`, even though the error was thrown at `myInner`.
297
+
298
+ ```ts index.ts icon="/icons/typescript.svg"
299
+ const fn = () => {
300
+ function myInner() {
301
+ throw err;
302
+ }
303
+
304
+ try {
305
+ myInner();
306
+ } catch (err) {
307
+ console.log(err.stack);
308
+ console.log("");
309
+ console.log("-- captureStackTrace --");
310
+ console.log("");
311
+ Error.captureStackTrace(err, fn);
312
+ console.log(err.stack);
313
+ }
314
+ };
315
+
316
+ fn();
317
+ ```
318
+
319
+ ```txt
320
+ Error: here!
321
+ at myInner (file.js:4:15)
322
+ at fn (file.js:8:5)
323
+ at module code (file.js:17:1)
324
+ at moduleEvaluation (native)
325
+ at moduleEvaluation (native)
326
+ at <anonymous> (native)
327
+
328
+ -- captureStackTrace --
329
+
330
+ Error: here!
331
+ at module code (file.js:17:1)
332
+ at moduleEvaluation (native)
333
+ at moduleEvaluation (native)
334
+ at <anonymous> (native)
335
+ ```
@@ -0,0 +1,214 @@
1
+ ---
2
+ title: "Environment Variables"
3
+ description: "Read and configure environment variables in Bun, including automatic .env file support"
4
+ ---
5
+
6
+ Bun reads your `.env` files automatically and provides idiomatic ways to read and write your environment variables programmatically. Plus, some aspects of Bun's runtime behavior can be configured with Bun-specific environment variables.
7
+
8
+ ## Setting environment variables
9
+
10
+ Bun reads the following files automatically (listed in order of increasing precedence).
11
+
12
+ - `.env`
13
+ - `.env.production`, `.env.development`, `.env.test` (depending on value of `NODE_ENV`)
14
+ - `.env.local`
15
+
16
+ ```txt .env icon="settings"
17
+ FOO=hello
18
+ BAR=world
19
+ ```
20
+
21
+ Variables can also be set via the command line.
22
+
23
+ <CodeGroup>
24
+
25
+ ```sh Linux/macOS icon="terminal"
26
+ FOO=helloworld bun run dev
27
+ ```
28
+
29
+ ```sh Windows icon="windows"
30
+ # Using CMD
31
+ set FOO=helloworld && bun run dev
32
+
33
+ # Using PowerShell
34
+ $env:FOO="helloworld"; bun run dev
35
+ ```
36
+
37
+ </CodeGroup>
38
+
39
+ <Accordion title="Cross-platform solution with Windows">
40
+
41
+ For a cross-platform solution, you can use [bun shell](/runtime/shell). For example, the `bun exec` command.
42
+
43
+ ```sh
44
+ bun exec 'FOO=helloworld bun run dev'
45
+ ```
46
+
47
+ On Windows, `package.json` scripts called with `bun run` will automatically use the **bun shell**, making the following also cross-platform.
48
+
49
+ ```json package.json
50
+ "scripts": {
51
+ "dev": "NODE_ENV=development bun --watch app.ts",
52
+ },
53
+ ```
54
+
55
+ </Accordion>
56
+
57
+ Or programmatically by assigning a property to `process.env`.
58
+
59
+ ```ts
60
+ process.env.FOO = "hello";
61
+ ```
62
+
63
+ ---
64
+
65
+ ## Manually specifying `.env` files
66
+
67
+ Bun supports `--env-file` to override which specific `.env` file to load. You can use `--env-file` when running scripts in bun's runtime, or when running package.json scripts.
68
+
69
+ ```sh
70
+ bun --env-file=.env.1 src/index.ts
71
+
72
+ bun --env-file=.env.abc --env-file=.env.def run build
73
+ ```
74
+
75
+ ---
76
+
77
+ ## Quotation marks
78
+
79
+ Bun supports double quotes, single quotes, and template literal backticks:
80
+
81
+ ```txt .env icon="settings"
82
+ FOO='hello'
83
+ FOO="hello"
84
+ FOO=`hello`
85
+ ```
86
+
87
+ ### Expansion
88
+
89
+ Environment variables are automatically _expanded_. This means you can reference previously-defined variables in your environment variables.
90
+
91
+ ```txt .env icon="settings"
92
+ FOO=world
93
+ BAR=hello$FOO
94
+ ```
95
+
96
+ ```ts
97
+ process.env.BAR; // => "helloworld"
98
+ ```
99
+
100
+ This is useful for constructing connection strings or other compound values.
101
+
102
+ ```txt .env icon="settings"
103
+ DB_USER=postgres
104
+ DB_PASSWORD=secret
105
+ DB_HOST=localhost
106
+ DB_PORT=5432
107
+ DB_URL=postgres://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME
108
+ ```
109
+
110
+ This can be disabled by escaping the `$` with a backslash.
111
+
112
+ ```txt .env icon="settings"
113
+ FOO=world
114
+ BAR=hello\$FOO
115
+ ```
116
+
117
+ ```ts
118
+ process.env.BAR; // => "hello$FOO"
119
+ ```
120
+
121
+ ### `dotenv`
122
+
123
+ Generally speaking, you won't need `dotenv` or `dotenv-expand` anymore, because Bun reads `.env` files automatically.
124
+
125
+ ## Reading environment variables
126
+
127
+ The current environment variables can be accessed via `process.env`.
128
+
129
+ ```ts
130
+ process.env.API_TOKEN; // => "secret"
131
+ ```
132
+
133
+ Bun also exposes these variables via `Bun.env` and `import.meta.env`, which is a simple alias of `process.env`.
134
+
135
+ ```ts
136
+ Bun.env.API_TOKEN; // => "secret"
137
+ import.meta.env.API_TOKEN; // => "secret"
138
+ ```
139
+
140
+ To print all currently-set environment variables to the command line, run `bun --print process.env`. This is useful for debugging.
141
+
142
+ ```sh
143
+ bun --print process.env
144
+ BAZ=stuff
145
+ FOOBAR=aaaaaa
146
+ <lots more lines>
147
+ ```
148
+
149
+ ## TypeScript
150
+
151
+ In TypeScript, all properties of `process.env` are typed as `string | undefined`.
152
+
153
+ ```ts
154
+ Bun.env.whatever;
155
+ // string | undefined
156
+ ```
157
+
158
+ To get autocompletion and tell TypeScript to treat a variable as a non-optional string, we'll use [interface merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#merging-interfaces).
159
+
160
+ ```ts
161
+ declare module "bun" {
162
+ interface Env {
163
+ AWESOME: string;
164
+ }
165
+ }
166
+ ```
167
+
168
+ Add this line to any file in your project. It will globally add the `AWESOME` property to `process.env` and `Bun.env`.
169
+
170
+ ```ts
171
+ process.env.AWESOME; // => string
172
+ ```
173
+
174
+ ## Configuring Bun
175
+
176
+ These environment variables are read by Bun and configure aspects of its behavior.
177
+
178
+ | Name | Description |
179
+ | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
180
+ | `NODE_TLS_REJECT_UNAUTHORIZED` | `NODE_TLS_REJECT_UNAUTHORIZED=0` disables SSL certificate validation. This is useful for testing and debugging, but you should be very hesitant to use this in production. Note: This environment variable was originally introduced by Node.js and we kept the name for compatibility. |
181
+ | `BUN_CONFIG_VERBOSE_FETCH` | If `BUN_CONFIG_VERBOSE_FETCH=curl`, then fetch requests will log the url, method, request headers and response headers to the console. This is useful for debugging network requests. This also works with `node:http`. `BUN_CONFIG_VERBOSE_FETCH=1` is equivalent to `BUN_CONFIG_VERBOSE_FETCH=curl` except without the `curl` output. |
182
+ | `BUN_RUNTIME_TRANSPILER_CACHE_PATH` | The runtime transpiler caches the transpiled output of source files larger than 50 kb. This makes CLIs using Bun load faster. If `BUN_RUNTIME_TRANSPILER_CACHE_PATH` is set, then the runtime transpiler will cache transpiled output to the specified directory. If `BUN_RUNTIME_TRANSPILER_CACHE_PATH` is set to an empty string or the string `"0"`, then the runtime transpiler will not cache transpiled output. If `BUN_RUNTIME_TRANSPILER_CACHE_PATH` is unset, then the runtime transpiler will cache transpiled output to the platform-specific cache directory. |
183
+ | `TMPDIR` | Bun occasionally requires a directory to store intermediate assets during bundling or other operations. If unset, defaults to the platform-specific temporary directory: `/tmp` on Linux, `/private/tmp` on macOS. |
184
+ | `NO_COLOR` | If `NO_COLOR=1`, then ANSI color output is [disabled](https://no-color.org/). |
185
+ | `FORCE_COLOR` | If `FORCE_COLOR=1`, then ANSI color output is force enabled, even if `NO_COLOR` is set. |
186
+ | `BUN_CONFIG_MAX_HTTP_REQUESTS` | Control the maximum number of concurrent HTTP requests sent by fetch and `bun install`. Defaults to `256`. If you are running into rate limits or connection issues, you can reduce this number. |
187
+ | `BUN_CONFIG_NO_CLEAR_TERMINAL_ON_RELOAD` | If `BUN_CONFIG_NO_CLEAR_TERMINAL_ON_RELOAD=true`, then `bun --watch` will not clear the console on reload |
188
+ | `DO_NOT_TRACK` | Disable uploading crash reports to `bun.report` on crash. On macOS & Windows, crash report uploads are enabled by default. Otherwise, telemetry is not sent yet as of May 21st, 2024, but we are planning to add telemetry in the coming weeks. If `DO_NOT_TRACK=1`, then auto-uploading crash reports and telemetry are both [disabled](https://do-not-track.dev/). |
189
+ | `BUN_OPTIONS` | Prepends command-line arguments to any Bun execution. For example, `BUN_OPTIONS="--hot"` makes `bun run dev` behave like `bun --hot run dev` |
190
+
191
+ ## Runtime transpiler caching
192
+
193
+ For files larger than 50 KB, Bun caches transpiled output into `$BUN_RUNTIME_TRANSPILER_CACHE_PATH` or the platform-specific cache directory. This makes CLIs using Bun load faster.
194
+
195
+ This transpiler cache is global and shared across all projects. It is safe to delete the cache at any time. It is a content-addressable cache, so it will never contain duplicate entries. It is also safe to delete the cache while a Bun process is running.
196
+
197
+ It is recommended to disable this cache when using ephemeral filesystems like Docker. Bun's Docker images automatically disable this cache.
198
+
199
+ ### Disable the runtime transpiler cache
200
+
201
+ To disable the runtime transpiler cache, set `BUN_RUNTIME_TRANSPILER_CACHE_PATH` to an empty string or the string `"0"`.
202
+
203
+ ```sh
204
+ BUN_RUNTIME_TRANSPILER_CACHE_PATH=0 bun run dev
205
+ ```
206
+
207
+ ### What does it cache?
208
+
209
+ It caches:
210
+
211
+ - The transpiled output of source files larger than 50 KB.
212
+ - The sourcemap for the transpiled output of the file
213
+
214
+ The file extension `.pile` is used for these cached files.