bun-types 1.3.2-canary.20251105T140650 → 1.3.2-canary.20251106T140813

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 (308) hide show
  1. package/docs/README.md +28 -0
  2. package/package.json +1 -1
  3. package/docs/api/binary-data.md +0 -1038
  4. package/docs/api/cc.md +0 -197
  5. package/docs/api/color.md +0 -262
  6. package/docs/api/console.md +0 -57
  7. package/docs/api/cookie.md +0 -449
  8. package/docs/api/dns.md +0 -110
  9. package/docs/api/fetch.md +0 -463
  10. package/docs/api/ffi.md +0 -557
  11. package/docs/api/file-io.md +0 -366
  12. package/docs/api/file-system-router.md +0 -112
  13. package/docs/api/file.md +0 -19
  14. package/docs/api/glob.md +0 -178
  15. package/docs/api/globals.md +0 -387
  16. package/docs/api/hashing.md +0 -319
  17. package/docs/api/html-rewriter.md +0 -334
  18. package/docs/api/http.md +0 -1408
  19. package/docs/api/import-meta.md +0 -69
  20. package/docs/api/node-api.md +0 -14
  21. package/docs/api/redis.md +0 -597
  22. package/docs/api/s3.md +0 -850
  23. package/docs/api/secrets.md +0 -319
  24. package/docs/api/semver.md +0 -52
  25. package/docs/api/spawn.md +0 -582
  26. package/docs/api/sql.md +0 -1374
  27. package/docs/api/sqlite.md +0 -694
  28. package/docs/api/streams.md +0 -230
  29. package/docs/api/tcp.md +0 -221
  30. package/docs/api/transpiler.md +0 -276
  31. package/docs/api/udp.md +0 -123
  32. package/docs/api/utils.md +0 -891
  33. package/docs/api/websockets.md +0 -573
  34. package/docs/api/workers.md +0 -322
  35. package/docs/api/yaml.md +0 -668
  36. package/docs/benchmarks.md +0 -120
  37. package/docs/bun-flavored-toml.md +0 -42
  38. package/docs/bundler/css.md +0 -1028
  39. package/docs/bundler/css_modules.md +0 -145
  40. package/docs/bundler/executables.md +0 -626
  41. package/docs/bundler/fullstack.md +0 -418
  42. package/docs/bundler/hmr.md +0 -234
  43. package/docs/bundler/html.md +0 -349
  44. package/docs/bundler/index.md +0 -1735
  45. package/docs/bundler/intro.md +0 -75
  46. package/docs/bundler/loaders.md +0 -410
  47. package/docs/bundler/macros.md +0 -329
  48. package/docs/bundler/plugins.md +0 -449
  49. package/docs/bundler/vs-esbuild.md +0 -1127
  50. package/docs/cli/add.md +0 -173
  51. package/docs/cli/bun-completions.md +0 -3
  52. package/docs/cli/bun-create.md +0 -338
  53. package/docs/cli/bun-install.md +0 -349
  54. package/docs/cli/bun-upgrade.md +0 -39
  55. package/docs/cli/bunx.md +0 -89
  56. package/docs/cli/filter.md +0 -90
  57. package/docs/cli/info.md +0 -65
  58. package/docs/cli/init.md +0 -85
  59. package/docs/cli/install.md +0 -344
  60. package/docs/cli/link.md +0 -40
  61. package/docs/cli/outdated.md +0 -90
  62. package/docs/cli/patch-commit.md +0 -11
  63. package/docs/cli/pm.md +0 -285
  64. package/docs/cli/publish.md +0 -120
  65. package/docs/cli/remove.md +0 -7
  66. package/docs/cli/run.md +0 -261
  67. package/docs/cli/test.md +0 -397
  68. package/docs/cli/unlink.md +0 -9
  69. package/docs/cli/update.md +0 -129
  70. package/docs/cli/why.md +0 -67
  71. package/docs/contributing/upgrading-webkit.md +0 -57
  72. package/docs/ecosystem/elysia.md +0 -24
  73. package/docs/ecosystem/express.md +0 -37
  74. package/docs/ecosystem/hono.md +0 -18
  75. package/docs/ecosystem/react.md +0 -65
  76. package/docs/ecosystem/stric.md +0 -38
  77. package/docs/guides/binary/arraybuffer-to-array.md +0 -27
  78. package/docs/guides/binary/arraybuffer-to-blob.md +0 -24
  79. package/docs/guides/binary/arraybuffer-to-buffer.md +0 -25
  80. package/docs/guides/binary/arraybuffer-to-string.md +0 -15
  81. package/docs/guides/binary/arraybuffer-to-typedarray.md +0 -39
  82. package/docs/guides/binary/blob-to-arraybuffer.md +0 -14
  83. package/docs/guides/binary/blob-to-dataview.md +0 -14
  84. package/docs/guides/binary/blob-to-stream.md +0 -14
  85. package/docs/guides/binary/blob-to-string.md +0 -15
  86. package/docs/guides/binary/blob-to-typedarray.md +0 -14
  87. package/docs/guides/binary/buffer-to-arraybuffer.md +0 -14
  88. package/docs/guides/binary/buffer-to-blob.md +0 -14
  89. package/docs/guides/binary/buffer-to-readablestream.md +0 -41
  90. package/docs/guides/binary/buffer-to-string.md +0 -25
  91. package/docs/guides/binary/buffer-to-typedarray.md +0 -14
  92. package/docs/guides/binary/dataview-to-string.md +0 -15
  93. package/docs/guides/binary/typedarray-to-arraybuffer.md +0 -25
  94. package/docs/guides/binary/typedarray-to-blob.md +0 -16
  95. package/docs/guides/binary/typedarray-to-buffer.md +0 -14
  96. package/docs/guides/binary/typedarray-to-dataview.md +0 -14
  97. package/docs/guides/binary/typedarray-to-readablestream.md +0 -41
  98. package/docs/guides/binary/typedarray-to-string.md +0 -16
  99. package/docs/guides/deployment/railway.md +0 -157
  100. package/docs/guides/ecosystem/astro.md +0 -72
  101. package/docs/guides/ecosystem/discordjs.md +0 -77
  102. package/docs/guides/ecosystem/docker.md +0 -140
  103. package/docs/guides/ecosystem/drizzle.md +0 -185
  104. package/docs/guides/ecosystem/edgedb.md +0 -228
  105. package/docs/guides/ecosystem/elysia.md +0 -31
  106. package/docs/guides/ecosystem/express.md +0 -40
  107. package/docs/guides/ecosystem/hono.md +0 -39
  108. package/docs/guides/ecosystem/mongoose.md +0 -87
  109. package/docs/guides/ecosystem/neon-drizzle.md +0 -220
  110. package/docs/guides/ecosystem/neon-serverless-postgres.md +0 -55
  111. package/docs/guides/ecosystem/nextjs.md +0 -49
  112. package/docs/guides/ecosystem/nuxt.md +0 -56
  113. package/docs/guides/ecosystem/pm2.md +0 -57
  114. package/docs/guides/ecosystem/prisma.md +0 -141
  115. package/docs/guides/ecosystem/qwik.md +0 -107
  116. package/docs/guides/ecosystem/react.md +0 -50
  117. package/docs/guides/ecosystem/remix.md +0 -78
  118. package/docs/guides/ecosystem/render.md +0 -79
  119. package/docs/guides/ecosystem/sentry.md +0 -52
  120. package/docs/guides/ecosystem/solidstart.md +0 -58
  121. package/docs/guides/ecosystem/ssr-react.md +0 -51
  122. package/docs/guides/ecosystem/stric.md +0 -55
  123. package/docs/guides/ecosystem/sveltekit.md +0 -125
  124. package/docs/guides/ecosystem/systemd.md +0 -113
  125. package/docs/guides/ecosystem/vite.md +0 -71
  126. package/docs/guides/html-rewriter/extract-links.md +0 -68
  127. package/docs/guides/html-rewriter/extract-social-meta.md +0 -93
  128. package/docs/guides/http/cluster.md +0 -66
  129. package/docs/guides/http/fetch-unix.md +0 -33
  130. package/docs/guides/http/fetch.md +0 -24
  131. package/docs/guides/http/file-uploads.md +0 -94
  132. package/docs/guides/http/hot.md +0 -26
  133. package/docs/guides/http/proxy.md +0 -24
  134. package/docs/guides/http/server.md +0 -46
  135. package/docs/guides/http/simple.md +0 -18
  136. package/docs/guides/http/stream-file.md +0 -48
  137. package/docs/guides/http/stream-iterator.md +0 -47
  138. package/docs/guides/http/stream-node-streams-in-bun.md +0 -20
  139. package/docs/guides/http/tls.md +0 -30
  140. package/docs/guides/install/add-dev.md +0 -26
  141. package/docs/guides/install/add-git.md +0 -36
  142. package/docs/guides/install/add-optional.md +0 -25
  143. package/docs/guides/install/add-peer.md +0 -43
  144. package/docs/guides/install/add-tarball.md +0 -33
  145. package/docs/guides/install/add.md +0 -42
  146. package/docs/guides/install/azure-artifacts.md +0 -73
  147. package/docs/guides/install/cicd.md +0 -41
  148. package/docs/guides/install/custom-registry.md +0 -30
  149. package/docs/guides/install/from-npm-install-to-bun-install.md +0 -214
  150. package/docs/guides/install/git-diff-bun-lockfile.md +0 -44
  151. package/docs/guides/install/jfrog-artifactory.md +0 -28
  152. package/docs/guides/install/npm-alias.md +0 -23
  153. package/docs/guides/install/registry-scope.md +0 -38
  154. package/docs/guides/install/trusted.md +0 -46
  155. package/docs/guides/install/workspaces.md +0 -70
  156. package/docs/guides/install/yarnlock.md +0 -44
  157. package/docs/guides/process/argv.md +0 -58
  158. package/docs/guides/process/ctrl-c.md +0 -16
  159. package/docs/guides/process/ipc.md +0 -66
  160. package/docs/guides/process/nanoseconds.md +0 -13
  161. package/docs/guides/process/os-signals.md +0 -39
  162. package/docs/guides/process/spawn-stderr.md +0 -31
  163. package/docs/guides/process/spawn-stdout.md +0 -26
  164. package/docs/guides/process/spawn.md +0 -41
  165. package/docs/guides/process/stdin.md +0 -54
  166. package/docs/guides/read-file/arraybuffer.md +0 -28
  167. package/docs/guides/read-file/buffer.md +0 -19
  168. package/docs/guides/read-file/exists.md +0 -16
  169. package/docs/guides/read-file/json.md +0 -17
  170. package/docs/guides/read-file/mime.md +0 -20
  171. package/docs/guides/read-file/stream.md +0 -26
  172. package/docs/guides/read-file/string.md +0 -22
  173. package/docs/guides/read-file/uint8array.md +0 -21
  174. package/docs/guides/read-file/watch.md +0 -68
  175. package/docs/guides/runtime/build-time-constants.md +0 -293
  176. package/docs/guides/runtime/cicd.md +0 -43
  177. package/docs/guides/runtime/codesign-macos-executable.md +0 -56
  178. package/docs/guides/runtime/define-constant.md +0 -145
  179. package/docs/guides/runtime/delete-directory.md +0 -37
  180. package/docs/guides/runtime/delete-file.md +0 -19
  181. package/docs/guides/runtime/heap-snapshot.md +0 -26
  182. package/docs/guides/runtime/import-html.md +0 -15
  183. package/docs/guides/runtime/import-json.md +0 -44
  184. package/docs/guides/runtime/import-toml.md +0 -30
  185. package/docs/guides/runtime/import-yaml.md +0 -102
  186. package/docs/guides/runtime/read-env.md +0 -32
  187. package/docs/guides/runtime/set-env.md +0 -47
  188. package/docs/guides/runtime/shell.md +0 -40
  189. package/docs/guides/runtime/timezone.md +0 -35
  190. package/docs/guides/runtime/tsconfig-paths.md +0 -29
  191. package/docs/guides/runtime/typescript.md +0 -49
  192. package/docs/guides/runtime/vscode-debugger.md +0 -47
  193. package/docs/guides/runtime/web-debugger.md +0 -82
  194. package/docs/guides/streams/node-readable-to-arraybuffer.md +0 -11
  195. package/docs/guides/streams/node-readable-to-blob.md +0 -11
  196. package/docs/guides/streams/node-readable-to-json.md +0 -12
  197. package/docs/guides/streams/node-readable-to-string.md +0 -12
  198. package/docs/guides/streams/node-readable-to-uint8array.md +0 -11
  199. package/docs/guides/streams/to-array.md +0 -14
  200. package/docs/guides/streams/to-arraybuffer.md +0 -14
  201. package/docs/guides/streams/to-blob.md +0 -14
  202. package/docs/guides/streams/to-buffer.md +0 -15
  203. package/docs/guides/streams/to-json.md +0 -14
  204. package/docs/guides/streams/to-string.md +0 -14
  205. package/docs/guides/streams/to-typedarray.md +0 -22
  206. package/docs/guides/test/bail.md +0 -22
  207. package/docs/guides/test/coverage-threshold.md +0 -60
  208. package/docs/guides/test/coverage.md +0 -44
  209. package/docs/guides/test/happy-dom.md +0 -68
  210. package/docs/guides/test/migrate-from-jest.md +0 -143
  211. package/docs/guides/test/mock-clock.md +0 -48
  212. package/docs/guides/test/mock-functions.md +0 -68
  213. package/docs/guides/test/rerun-each.md +0 -14
  214. package/docs/guides/test/run-tests.md +0 -111
  215. package/docs/guides/test/skip-tests.md +0 -39
  216. package/docs/guides/test/snapshot.md +0 -95
  217. package/docs/guides/test/spy-on.md +0 -46
  218. package/docs/guides/test/svelte-test.md +0 -120
  219. package/docs/guides/test/testing-library.md +0 -92
  220. package/docs/guides/test/timeout.md +0 -15
  221. package/docs/guides/test/todo-tests.md +0 -67
  222. package/docs/guides/test/update-snapshots.md +0 -46
  223. package/docs/guides/test/watch-mode.md +0 -19
  224. package/docs/guides/util/base64.md +0 -15
  225. package/docs/guides/util/deep-equals.md +0 -39
  226. package/docs/guides/util/deflate.md +0 -18
  227. package/docs/guides/util/detect-bun.md +0 -23
  228. package/docs/guides/util/entrypoint.md +0 -17
  229. package/docs/guides/util/escape-html.md +0 -22
  230. package/docs/guides/util/file-url-to-path.md +0 -14
  231. package/docs/guides/util/gzip.md +0 -18
  232. package/docs/guides/util/hash-a-password.md +0 -54
  233. package/docs/guides/util/import-meta-dir.md +0 -13
  234. package/docs/guides/util/import-meta-file.md +0 -13
  235. package/docs/guides/util/import-meta-path.md +0 -13
  236. package/docs/guides/util/javascript-uuid.md +0 -23
  237. package/docs/guides/util/main.md +0 -32
  238. package/docs/guides/util/path-to-file-url.md +0 -14
  239. package/docs/guides/util/sleep.md +0 -22
  240. package/docs/guides/util/version.md +0 -21
  241. package/docs/guides/util/which-path-to-executable-bin.md +0 -15
  242. package/docs/guides/websocket/compression.md +0 -31
  243. package/docs/guides/websocket/context.md +0 -77
  244. package/docs/guides/websocket/pubsub.md +0 -41
  245. package/docs/guides/websocket/simple.md +0 -33
  246. package/docs/guides/write-file/append.md +0 -52
  247. package/docs/guides/write-file/basic.md +0 -44
  248. package/docs/guides/write-file/blob.md +0 -28
  249. package/docs/guides/write-file/cat.md +0 -17
  250. package/docs/guides/write-file/file-cp.md +0 -16
  251. package/docs/guides/write-file/filesink.md +0 -52
  252. package/docs/guides/write-file/response.md +0 -17
  253. package/docs/guides/write-file/stdout.md +0 -21
  254. package/docs/guides/write-file/stream.md +0 -17
  255. package/docs/guides/write-file/unlink.md +0 -16
  256. package/docs/index.md +0 -77
  257. package/docs/install/audit.md +0 -57
  258. package/docs/install/cache.md +0 -59
  259. package/docs/install/catalogs.md +0 -298
  260. package/docs/install/index.md +0 -248
  261. package/docs/install/isolated.md +0 -197
  262. package/docs/install/lifecycle.md +0 -46
  263. package/docs/install/lockfile.md +0 -58
  264. package/docs/install/npmrc.md +0 -105
  265. package/docs/install/overrides.md +0 -73
  266. package/docs/install/patch.md +0 -59
  267. package/docs/install/registries.md +0 -30
  268. package/docs/install/security-scanner-api.md +0 -81
  269. package/docs/install/workspaces.md +0 -114
  270. package/docs/installation.md +0 -327
  271. package/docs/project/asan.md +0 -124
  272. package/docs/project/benchmarking.md +0 -203
  273. package/docs/project/bindgen.md +0 -225
  274. package/docs/project/building-windows.md +0 -162
  275. package/docs/project/contributing.md +0 -347
  276. package/docs/project/internals/build-process-for-ci.md +0 -75
  277. package/docs/project/licensing.md +0 -73
  278. package/docs/project/roadmap.md +0 -87
  279. package/docs/quickstart.md +0 -157
  280. package/docs/runtime/autoimport.md +0 -94
  281. package/docs/runtime/bun-apis.md +0 -207
  282. package/docs/runtime/bunfig.md +0 -772
  283. package/docs/runtime/debugger.md +0 -325
  284. package/docs/runtime/env.md +0 -253
  285. package/docs/runtime/hot.md +0 -145
  286. package/docs/runtime/index.md +0 -312
  287. package/docs/runtime/jsx.md +0 -385
  288. package/docs/runtime/loaders.md +0 -130
  289. package/docs/runtime/modules.md +0 -320
  290. package/docs/runtime/nodejs-apis.md +0 -463
  291. package/docs/runtime/plugins.md +0 -561
  292. package/docs/runtime/shell.md +0 -605
  293. package/docs/runtime/typescript.md +0 -139
  294. package/docs/runtime/web-apis.md +0 -128
  295. package/docs/test/configuration.md +0 -154
  296. package/docs/test/coverage.md +0 -142
  297. package/docs/test/discovery.md +0 -85
  298. package/docs/test/dom.md +0 -75
  299. package/docs/test/examples/concurrent-test-glob.md +0 -132
  300. package/docs/test/hot.md +0 -15
  301. package/docs/test/lifecycle.md +0 -81
  302. package/docs/test/mocks.md +0 -313
  303. package/docs/test/reporters.md +0 -117
  304. package/docs/test/runtime-behavior.md +0 -95
  305. package/docs/test/snapshots.md +0 -68
  306. package/docs/test/time.md +0 -126
  307. package/docs/test/writing.md +0 -825
  308. package/docs/typescript.md +0 -53
@@ -1,325 +0,0 @@
1
- ---
2
- name: Debugging
3
- ---
4
-
5
- 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.
6
-
7
- ## Debugging JavaScript and TypeScript
8
-
9
- ```ts#server.ts
10
- Bun.serve({
11
- fetch(req){
12
- console.log(req.url);
13
- return new Response("Hello, world!");
14
- }
15
- })
16
- ```
17
-
18
- ### `--inspect`
19
-
20
- 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.
21
-
22
- ```sh
23
- $ bun --inspect server.ts
24
- ------------------ Bun Inspector ------------------
25
- Listening at:
26
- ws://localhost:6499/0tqxs9exrgrm
27
-
28
- Inspect in browser:
29
- https://debug.bun.sh/#localhost:6499/0tqxs9exrgrm
30
- ------------------ Bun Inspector ------------------
31
- ```
32
-
33
- ### `--inspect-brk`
34
-
35
- 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.
36
-
37
- ### `--inspect-wait`
38
-
39
- The `--inspect-wait` flag behaves identically to `--inspect`, except the code will not execute until a debugger has attached to the running process.
40
-
41
- ### Setting a port or URL for the debugger
42
-
43
- Regardless of which flag you use, you can optionally specify a port number, URL prefix, or both.
44
-
45
- ```sh
46
- $ bun --inspect=4000 server.ts
47
- $ bun --inspect=localhost:4000 server.ts
48
- $ bun --inspect=localhost:4000/prefix server.ts
49
- ```
50
-
51
- ## Debuggers
52
-
53
- Various debugging tools can connect to this server to provide an interactive debugging experience.
54
-
55
- ### `debug.bun.sh`
56
-
57
- 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.
58
-
59
- 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.
60
-
61
- {% image src="https://github.com/oven-sh/bun/assets/3084745/e6a976a8-80cc-4394-8925-539025cc025d" alt="Screenshot of Bun debugger, Console tab" /%}
62
-
63
- 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.
64
-
65
- {% image src="https://github.com/oven-sh/bun/assets/3084745/3b69c7e9-25ff-4f9d-acc4-caa736862935" alt="screenshot of Bun debugger" /%}
66
-
67
- 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.
68
-
69
- Note how the UI has changed.
70
-
71
- {% image src="https://github.com/oven-sh/bun/assets/3084745/8b565e58-5445-4061-9bc4-f41090dfe769" alt="screenshot of Bun debugger" /%}
72
-
73
- 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.
74
-
75
- {% image src="https://github.com/oven-sh/bun/assets/3084745/f4312b76-48ba-4a7d-b3b6-6205968ac681" /%}
76
-
77
- 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.
78
-
79
- {% image src="https://github.com/oven-sh/bun/assets/3084745/63d7f843-5180-489c-aa94-87c486e68646" /%}
80
-
81
- In the upper left of the Sources pane, we can control the execution of the program.
82
-
83
- {% image src="https://github.com/oven-sh/bun/assets/3084745/41b76deb-7371-4461-9d5d-81b5a6d2f7a4" /%}
84
-
85
- Here's a cheat sheet explaining the functions of the control flow buttons.
86
-
87
- - _Continue script execution_ — continue running the program until the next breakpoint or exception.
88
- - _Step over_ — The program will continue to the next line.
89
- - _Step into_ — If the current statement contains a function call, the debugger will "step into" the called function.
90
- - _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.
91
-
92
- {% image src="https://github-production-user-asset-6210df.s3.amazonaws.com/3084745/261510346-6a94441c-75d3-413a-99a7-efa62365f83d.png" /%}
93
-
94
- ### Visual Studio Code Debugger
95
-
96
- 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).
97
-
98
- ## Debugging Network Requests
99
-
100
- The `BUN_CONFIG_VERBOSE_FETCH` environment variable lets you log network requests made with `fetch()` or `node:http` automatically.
101
-
102
- | Value | Description |
103
- | ------- | ---------------------------------- |
104
- | `curl` | Print requests as `curl` commands. |
105
- | `true` | Print request & response info |
106
- | `false` | Don't print anything. Default |
107
-
108
- ### Print fetch & node:http requests as curl commands
109
-
110
- Bun also supports printing `fetch()` and `node:http` network requests as `curl` commands by setting the environment variable `BUN_CONFIG_VERBOSE_FETCH` to `curl`.
111
-
112
- ```ts
113
- process.env.BUN_CONFIG_VERBOSE_FETCH = "curl";
114
-
115
- await fetch("https://example.com", {
116
- method: "POST",
117
- headers: {
118
- "Content-Type": "application/json",
119
- },
120
- body: JSON.stringify({ foo: "bar" }),
121
- });
122
- ```
123
-
124
- This prints the `fetch` request as a single-line `curl` command to let you copy-paste into your terminal to replicate the request.
125
-
126
- ```sh
127
- [fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.3.2-canary.20251105T140650" -H "Accept: */*" -H "Host: example.com" -H "Accept-Encoding: gzip, deflate, br" --compressed -H "Content-Length: 13" --data-raw "{\"foo\":\"bar\"}"
128
- [fetch] > HTTP/1.1 POST https://example.com/
129
- [fetch] > content-type: application/json
130
- [fetch] > Connection: keep-alive
131
- [fetch] > User-Agent: Bun/1.3.2-canary.20251105T140650
132
- [fetch] > Accept: */*
133
- [fetch] > Host: example.com
134
- [fetch] > Accept-Encoding: gzip, deflate, br
135
- [fetch] > Content-Length: 13
136
-
137
- [fetch] < 200 OK
138
- [fetch] < Accept-Ranges: bytes
139
- [fetch] < Cache-Control: max-age=604800
140
- [fetch] < Content-Type: text/html; charset=UTF-8
141
- [fetch] < Date: Tue, 18 Jun 2024 05:12:07 GMT
142
- [fetch] < Etag: "3147526947"
143
- [fetch] < Expires: Tue, 25 Jun 2024 05:12:07 GMT
144
- [fetch] < Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
145
- [fetch] < Server: EOS (vny/044F)
146
- [fetch] < Content-Length: 1256
147
- ```
148
-
149
- The lines with `[fetch] >` are the request from your local code, and the lines with `[fetch] <` are the response from the remote server.
150
-
151
- The `BUN_CONFIG_VERBOSE_FETCH` environment variable is supported in both `fetch()` and `node:http` requests, so it should just work.
152
-
153
- To print without the `curl` command, set `BUN_CONFIG_VERBOSE_FETCH` to `true`.
154
-
155
- ```ts
156
- process.env.BUN_CONFIG_VERBOSE_FETCH = "true";
157
-
158
- await fetch("https://example.com", {
159
- method: "POST",
160
- headers: {
161
- "Content-Type": "application/json",
162
- },
163
- body: JSON.stringify({ foo: "bar" }),
164
- });
165
- ```
166
-
167
- This prints the following to the console:
168
-
169
- ```sh
170
- [fetch] > HTTP/1.1 POST https://example.com/
171
- [fetch] > content-type: application/json
172
- [fetch] > Connection: keep-alive
173
- [fetch] > User-Agent: Bun/1.3.2-canary.20251105T140650
174
- [fetch] > Accept: */*
175
- [fetch] > Host: example.com
176
- [fetch] > Accept-Encoding: gzip, deflate, br
177
- [fetch] > Content-Length: 13
178
-
179
- [fetch] < 200 OK
180
- [fetch] < Accept-Ranges: bytes
181
- [fetch] < Cache-Control: max-age=604800
182
- [fetch] < Content-Type: text/html; charset=UTF-8
183
- [fetch] < Date: Tue, 18 Jun 2024 05:12:07 GMT
184
- [fetch] < Etag: "3147526947"
185
- [fetch] < Expires: Tue, 25 Jun 2024 05:12:07 GMT
186
- [fetch] < Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
187
- [fetch] < Server: EOS (vny/044F)
188
- [fetch] < Content-Length: 1256
189
- ```
190
-
191
- ## Stacktraces & sourcemaps
192
-
193
- 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.
194
-
195
- <!-- TODO: uncomment once v1.1.13 regression is fixed (cc @paperclover) -->
196
- <!-- In Bun, each `Error` object gets four additional properties:
197
-
198
- - `line` — the source-mapped line number. This number points to the input source code, not the transpiled output.
199
- - `column` — the source-mapped column number. This number points to the input source code, not the transpiled output.
200
- - `originalColumn` — the column number pointing to transpiled source code, without sourcemaps. This number comes from JavaScriptCore.
201
- - `originalLine` — the line number pointing to transpiled source code, without sourcemaps. This number comes from JavaScriptCore.
202
-
203
- These properties are populated lazily when `error.stack` is accessed. -->
204
-
205
- Bun automatically loads sourcemaps both at runtime when transpiling files on-demand, and when using `bun build` to precompile files ahead of time.
206
-
207
- ### Syntax-highlighted source code preview
208
-
209
- 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)`:
210
-
211
- ```ts
212
- // Create an error
213
- const err = new Error("Something went wrong");
214
- console.log(Bun.inspect(err, { colors: true }));
215
- ```
216
-
217
- This prints a syntax-highlighted preview of the source code where the error occurred, along with the error message and stack trace.
218
-
219
- ```js
220
- 1 | // Create an error
221
- 2 | const err = new Error("Something went wrong");
222
- ^
223
- error: Something went wrong
224
- at file.js:2:13
225
- ```
226
-
227
- ### V8 Stack Traces
228
-
229
- 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.
230
-
231
- 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.
232
-
233
- #### V8 Stack Trace API
234
-
235
- 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.
236
-
237
- ##### Error.prepareStackTrace
238
-
239
- 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.
240
-
241
- ```ts
242
- Error.prepareStackTrace = (err, stack) => {
243
- return stack.map(callSite => {
244
- return callSite.getFileName();
245
- });
246
- };
247
-
248
- const err = new Error("Something went wrong");
249
- console.log(err.stack);
250
- // [ "error.js" ]
251
- ```
252
-
253
- The `CallSite` object has the following methods:
254
-
255
- | Method | Returns |
256
- | -------------------------- | ----------------------------------------------------- |
257
- | `getThis` | `this` value of the function call |
258
- | `getTypeName` | typeof `this` |
259
- | `getFunction` | function object |
260
- | `getFunctionName` | function name as a string |
261
- | `getMethodName` | method name as a string |
262
- | `getFileName` | file name or URL |
263
- | `getLineNumber` | line number |
264
- | `getColumnNumber` | column number |
265
- | `getEvalOrigin` | `undefined` |
266
- | `getScriptNameOrSourceURL` | source URL |
267
- | `isToplevel` | returns `true` if the function is in the global scope |
268
- | `isEval` | returns `true` if the function is an `eval` call |
269
- | `isNative` | returns `true` if the function is native |
270
- | `isConstructor` | returns `true` if the function is a constructor |
271
- | `isAsync` | returns `true` if the function is `async` |
272
- | `isPromiseAll` | Not implemented yet. |
273
- | `getPromiseIndex` | Not implemented yet. |
274
- | `toString` | returns a string representation of the call site |
275
-
276
- In some cases, the `Function` object may have already been garbage collected, so some of these methods may return `undefined`.
277
-
278
- ##### Error.captureStackTrace(error, startFn)
279
-
280
- 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.
281
-
282
- 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.
283
-
284
- For example, the below code will make `err.stack` point to the code calling `fn()`, even though the error was thrown at `myInner`.
285
-
286
- ```ts
287
- const fn = () => {
288
- function myInner() {
289
- throw err;
290
- }
291
-
292
- try {
293
- myInner();
294
- } catch (err) {
295
- console.log(err.stack);
296
- console.log("");
297
- console.log("-- captureStackTrace --");
298
- console.log("");
299
- Error.captureStackTrace(err, fn);
300
- console.log(err.stack);
301
- }
302
- };
303
-
304
- fn();
305
- ```
306
-
307
- This logs the following:
308
-
309
- ```sh
310
- Error: here!
311
- at myInner (file.js:4:15)
312
- at fn (file.js:8:5)
313
- at module code (file.js:17:1)
314
- at moduleEvaluation (native)
315
- at moduleEvaluation (native)
316
- at <anonymous> (native)
317
-
318
- -- captureStackTrace --
319
-
320
- Error: here!
321
- at module code (file.js:17:1)
322
- at moduleEvaluation (native)
323
- at moduleEvaluation (native)
324
- at <anonymous> (native)
325
- ```
@@ -1,253 +0,0 @@
1
- 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.
2
-
3
- ## Setting environment variables
4
-
5
- Bun reads the following files automatically (listed in order of increasing precedence).
6
-
7
- - `.env`
8
- - `.env.production`, `.env.development`, `.env.test` (depending on value of `NODE_ENV`)
9
- - `.env.local`
10
-
11
- {% callout %}
12
- **Note:** When `NODE_ENV=test`, `.env.local` is **not** loaded. This ensures consistent test environments across different executions by preventing local overrides during testing. This behavior matches popular frameworks like [Next.js](https://nextjs.org/docs/pages/guides/environment-variables#test-environment-variables) and [Create React App](https://create-react-app.dev/docs/adding-custom-environment-variables/#what-other-env-files-can-be-used).
13
- {% /callout %}
14
-
15
- ```txt#.env
16
- FOO=hello
17
- BAR=world
18
- ```
19
-
20
- Variables can also be set via the command line.
21
-
22
- {% codetabs %}
23
-
24
- ```sh#Linux/macOS
25
- $ FOO=helloworld bun run dev
26
- ```
27
-
28
- ```sh#Windows
29
- # Using CMD
30
- $ set FOO=helloworld && bun run dev
31
-
32
- # Using PowerShell
33
- $ $env:FOO="helloworld"; bun run dev
34
- ```
35
-
36
- {% /codetabs %}
37
-
38
- {% details summary="Cross-platform solution with Windows" %}
39
-
40
- For a cross-platform solution, you can use [bun shell](https://bun.com/docs/runtime/shell). For example, the `bun exec` command.
41
-
42
- ```sh
43
- $ bun exec 'FOO=helloworld bun run dev'
44
- ```
45
-
46
- On Windows, `package.json` scripts called with `bun run` will automatically use the **bun shell**, making the following also cross-platform.
47
-
48
- ```json#package.json
49
- "scripts": {
50
- "dev": "NODE_ENV=development bun --watch app.ts",
51
- },
52
- ```
53
-
54
- {% /details %}
55
-
56
- Or programmatically by assigning a property to `process.env`.
57
-
58
- ```ts
59
- process.env.FOO = "hello";
60
- ```
61
-
62
- ### Manually specifying `.env` files
63
-
64
- 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.
65
-
66
- ```sh
67
- $ bun --env-file=.env.1 src/index.ts
68
-
69
- $ bun --env-file=.env.abc --env-file=.env.def run build
70
- ```
71
-
72
- ### Quotation marks
73
-
74
- Bun supports double quotes, single quotes, and template literal backticks:
75
-
76
- ```txt#.env
77
- FOO='hello'
78
- FOO="hello"
79
- FOO=`hello`
80
- ```
81
-
82
- ### Expansion
83
-
84
- Environment variables are automatically _expanded_. This means you can reference previously-defined variables in your environment variables.
85
-
86
- ```txt#.env
87
- FOO=world
88
- BAR=hello$FOO
89
- ```
90
-
91
- ```ts
92
- process.env.BAR; // => "helloworld"
93
- ```
94
-
95
- This is useful for constructing connection strings or other compound values.
96
-
97
- ```txt#.env
98
- DB_USER=postgres
99
- DB_PASSWORD=secret
100
- DB_HOST=localhost
101
- DB_PORT=5432
102
- DB_URL=postgres://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME
103
- ```
104
-
105
- This can be disabled by escaping the `$` with a backslash.
106
-
107
- ```txt#.env
108
- FOO=world
109
- BAR=hello\$FOO
110
- ```
111
-
112
- ```ts
113
- process.env.BAR; // => "hello$FOO"
114
- ```
115
-
116
- ### `dotenv`
117
-
118
- Generally speaking, you won't need `dotenv` or `dotenv-expand` anymore, because Bun reads `.env` files automatically.
119
-
120
- ## Reading environment variables
121
-
122
- The current environment variables can be accessed via `process.env`.
123
-
124
- ```ts
125
- process.env.API_TOKEN; // => "secret"
126
- ```
127
-
128
- Bun also exposes these variables via `Bun.env` and `import.meta.env`, which is a simple alias of `process.env`.
129
-
130
- ```ts
131
- Bun.env.API_TOKEN; // => "secret"
132
- import.meta.env.API_TOKEN; // => "secret"
133
- ```
134
-
135
- To print all currently-set environment variables to the command line, run `bun --print process.env`. This is useful for debugging.
136
-
137
- ```sh
138
- $ bun --print process.env
139
- BAZ=stuff
140
- FOOBAR=aaaaaa
141
- <lots more lines>
142
- ```
143
-
144
- ## TypeScript
145
-
146
- In TypeScript, all properties of `process.env` are typed as `string | undefined`.
147
-
148
- ```ts
149
- Bun.env.whatever;
150
- // string | undefined
151
- ```
152
-
153
- 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).
154
-
155
- ```ts
156
- declare module "bun" {
157
- interface Env {
158
- AWESOME: string;
159
- }
160
- }
161
- ```
162
-
163
- Add this line to any file in your project. It will globally add the `AWESOME` property to `process.env` and `Bun.env`.
164
-
165
- ```ts
166
- process.env.AWESOME; // => string
167
- ```
168
-
169
- ## Configuring Bun
170
-
171
- These environment variables are read by Bun and configure aspects of its behavior.
172
-
173
- {% table %}
174
-
175
- - Name
176
- - Description
177
-
178
- ---
179
-
180
- - `NODE_TLS_REJECT_UNAUTHORIZED`
181
- - `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.
182
-
183
- ---
184
-
185
- - `BUN_CONFIG_VERBOSE_FETCH`
186
- - 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.
187
-
188
- ---
189
-
190
- - `BUN_RUNTIME_TRANSPILER_CACHE_PATH`
191
- - 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.
192
-
193
- ---
194
-
195
- - `TMPDIR`
196
- - 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.
197
-
198
- ---
199
-
200
- - `NO_COLOR`
201
- - If `NO_COLOR=1`, then ANSI color output is [disabled](https://no-color.org/).
202
-
203
- ---
204
-
205
- - `FORCE_COLOR`
206
- - If `FORCE_COLOR=1`, then ANSI color output is force enabled, even if `NO_COLOR` is set.
207
-
208
- ---
209
-
210
- - `BUN_CONFIG_MAX_HTTP_REQUESTS`
211
- - 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.
212
-
213
- ---
214
-
215
- - `BUN_CONFIG_NO_CLEAR_TERMINAL_ON_RELOAD`
216
- - If `BUN_CONFIG_NO_CLEAR_TERMINAL_ON_RELOAD=true`, then `bun --watch` will not clear the console on reload
217
-
218
- ---
219
-
220
- - `DO_NOT_TRACK`
221
- - 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/).
222
-
223
- ---
224
-
225
- - `BUN_OPTIONS`
226
- - Prepends command-line arguments to any Bun execution. For example, `BUN_OPTIONS="--hot"` makes `bun run dev` behave like `bun --hot run dev`.
227
-
228
- {% /table %}
229
-
230
- ## Runtime transpiler caching
231
-
232
- 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.
233
-
234
- 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.
235
-
236
- It is recommended to disable this cache when using ephemeral filesystems like Docker. Bun's Docker images automatically disable this cache.
237
-
238
- ### Disable the runtime transpiler cache
239
-
240
- To disable the runtime transpiler cache, set `BUN_RUNTIME_TRANSPILER_CACHE_PATH` to an empty string or the string `"0"`.
241
-
242
- ```sh
243
- BUN_RUNTIME_TRANSPILER_CACHE_PATH=0 bun run dev
244
- ```
245
-
246
- ### What does it cache?
247
-
248
- It caches:
249
-
250
- - The transpiled output of source files larger than 50 KB.
251
- - The sourcemap for the transpiled output of the file
252
-
253
- The file extension `.pile` is used for these cached files.