bun-types 1.3.2-canary.20251106T140813 → 1.3.2

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,129 @@
1
+ ---
2
+ title: UDP
3
+ description: Use Bun's UDP API to implement services with advanced real-time requirements, such as voice chat.
4
+ ---
5
+
6
+ ## Bind a UDP socket (`Bun.udpSocket()`)
7
+
8
+ To create a new (bound) UDP socket:
9
+
10
+ ```ts
11
+ const socket = await Bun.udpSocket({});
12
+ console.log(socket.port); // assigned by the operating system
13
+ ```
14
+
15
+ Specify a port:
16
+
17
+ ```ts
18
+ const socket = await Bun.udpSocket({
19
+ port: 41234, // [!code ++]
20
+ });
21
+
22
+ console.log(socket.port); // 41234
23
+ ```
24
+
25
+ ### Send a datagram
26
+
27
+ Specify the data to send, as well as the destination port and address.
28
+
29
+ ```ts
30
+ socket.send("Hello, world!", 41234, "127.0.0.1");
31
+ ```
32
+
33
+ Note that the address must be a valid IP address - `send` does not perform
34
+ DNS resolution, as it is intended for low-latency operations.
35
+
36
+ ### Receive datagrams
37
+
38
+ When creating your socket, add a callback to specify what should be done when packets are received:
39
+
40
+ ```ts server.ts icon="/icons/typescript.svg"
41
+ const server = await Bun.udpSocket({
42
+ socket: {
43
+ data(socket, buf, port, addr) {
44
+ console.log(`message from ${addr}:${port}:`);
45
+ console.log(buf.toString());
46
+ },
47
+ },
48
+ });
49
+
50
+ const client = await Bun.udpSocket({});
51
+ client.send("Hello!", server.port, "127.0.0.1");
52
+ ```
53
+
54
+ ### Connections
55
+
56
+ While UDP does not have a concept of a connection, many UDP communications (especially as a client) involve only one peer.
57
+ In such cases it can be beneficial to connect the socket to that peer, which specifies to which address all packets are sent
58
+ and restricts incoming packets to that peer only.
59
+
60
+ ```ts server.ts icon="/icons/typescript.svg"
61
+ const server = await Bun.udpSocket({
62
+ socket: {
63
+ data(socket, buf, port, addr) {
64
+ console.log(`message from ${addr}:${port}:`);
65
+ console.log(buf.toString());
66
+ },
67
+ },
68
+ });
69
+
70
+ const client = await Bun.udpSocket({
71
+ connect: {
72
+ port: server.port,
73
+ hostname: "127.0.0.1",
74
+ },
75
+ });
76
+
77
+ client.send("Hello");
78
+ ```
79
+
80
+ Because connections are implemented on the operating system level, you can potentially observe performance benefits, too.
81
+
82
+ ### Send many packets at once using `sendMany()`
83
+
84
+ If you want to send a large volume of packets at once, it can make sense to batch them all together to avoid the overhead
85
+ of making a system call for each. This is made possible by the `sendMany()` API:
86
+
87
+ For an unconnected socket, `sendMany` takes an array as its only argument. Each set of three array elements describes a packet:
88
+ The first item is the data to be sent, the second is the target port, and the last is the target address.
89
+
90
+ ```ts server.ts icon="/icons/typescript.svg"
91
+ const socket = await Bun.udpSocket({});
92
+
93
+ // sends 'Hello' to 127.0.0.1:41234, and 'foo' to 1.1.1.1:53 in a single operation
94
+ socket.sendMany(["Hello", 41234, "127.0.0.1", "foo", 53, "1.1.1.1"]);
95
+ ```
96
+
97
+ With a connected socket, `sendMany` simply takes an array, where each element represents the data to be sent to the peer.
98
+
99
+ ```ts server.ts icon="/icons/typescript.svg"
100
+ const socket = await Bun.udpSocket({
101
+ connect: {
102
+ port: 41234,
103
+ hostname: "localhost",
104
+ },
105
+ });
106
+
107
+ socket.sendMany(["foo", "bar", "baz"]);
108
+ ```
109
+
110
+ `sendMany` returns the number of packets that were successfully sent. As with `send`, `sendMany` only takes valid IP addresses
111
+ as destinations, as it does not perform DNS resolution.
112
+
113
+ ### Handle backpressure
114
+
115
+ It may happen that a packet that you're sending does not fit into the operating system's packet buffer. You can detect that this
116
+ has happened when:
117
+
118
+ - `send` returns `false`
119
+ - `sendMany` returns a number smaller than the number of packets you specified. In this case, the `drain` socket handler will be called once the socket becomes writable again:
120
+
121
+ ```ts
122
+ const socket = await Bun.udpSocket({
123
+ socket: {
124
+ drain(socket) {
125
+ // continue sending data
126
+ },
127
+ },
128
+ });
129
+ ```
@@ -0,0 +1,19 @@
1
+ ---
2
+ title: Node-API
3
+ description: Use Bun's Node-API module to build native add-ons to Node.js
4
+ ---
5
+
6
+ Node-API is an interface for building native add-ons to Node.js. Bun implements 95% of this interface from scratch, so most existing Node-API extensions will work with Bun out of the box. Track the completion status of it in [this issue](https://github.com/oven-sh/bun/issues/158).
7
+
8
+ As in Node.js, `.node` files (Node-API modules) can be required directly in Bun.
9
+
10
+ ```js
11
+ const napi = require("./my-node-module.node");
12
+ ```
13
+
14
+ Alternatively, use `process.dlopen`:
15
+
16
+ ```js
17
+ let mod = { exports: {} };
18
+ process.dlopen(mod, "./my-node-module.node");
19
+ ```
@@ -0,0 +1,468 @@
1
+ ---
2
+ title: "Node.js Compatibility"
3
+ description: "Bun's compatibility status with Node.js APIs, modules, and globals"
4
+ ---
5
+
6
+ Every day, Bun gets closer to 100% Node.js API compatibility. Today, popular frameworks like Next.js, Express, and millions of `npm` packages intended for Node just work with Bun. To ensure compatibility, we run thousands of tests from Node.js' test suite before every release of Bun.
7
+
8
+ **If a package works in Node.js but doesn't work in Bun, we consider it a bug in Bun.** Please [open an issue](https://bun.com/issues) and we'll fix it.
9
+
10
+ This page is updated regularly to reflect compatibility status of the latest version of Bun. The information below reflects Bun's compatibility with _Node.js v23_.
11
+
12
+ ## Built-in Node.js modules
13
+
14
+ ### [`node:assert`](https://nodejs.org/api/assert.html)
15
+
16
+ 🟢 Fully implemented.
17
+
18
+ ### [`node:buffer`](https://nodejs.org/api/buffer.html)
19
+
20
+ 🟢 Fully implemented.
21
+
22
+ ### [`node:console`](https://nodejs.org/api/console.html)
23
+
24
+ 🟢 Fully implemented.
25
+
26
+ ### [`node:dgram`](https://nodejs.org/api/dgram.html)
27
+
28
+ 🟢 Fully implemented. > 90% of Node.js's test suite passes.
29
+
30
+ ### [`node:diagnostics_channel`](https://nodejs.org/api/diagnostics_channel.html)
31
+
32
+ 🟢 Fully implemented.
33
+
34
+ ### [`node:dns`](https://nodejs.org/api/dns.html)
35
+
36
+ 🟢 Fully implemented. > 90% of Node.js's test suite passes.
37
+
38
+ ### [`node:events`](https://nodejs.org/api/events.html)
39
+
40
+ 🟢 Fully implemented. 100% of Node.js's test suite passes. `EventEmitterAsyncResource` uses `AsyncResource` underneath.
41
+
42
+ ### [`node:fs`](https://nodejs.org/api/fs.html)
43
+
44
+ 🟢 Fully implemented. 92% of Node.js's test suite passes.
45
+
46
+ ### [`node:http`](https://nodejs.org/api/http.html)
47
+
48
+ 🟢 Fully implemented. Outgoing client request body is currently buffered instead of streamed.
49
+
50
+ ### [`node:https`](https://nodejs.org/api/https.html)
51
+
52
+ 🟢 APIs are implemented, but `Agent` is not always used yet.
53
+
54
+ ### [`node:os`](https://nodejs.org/api/os.html)
55
+
56
+ 🟢 Fully implemented. 100% of Node.js's test suite passes.
57
+
58
+ ### [`node:path`](https://nodejs.org/api/path.html)
59
+
60
+ 🟢 Fully implemented. 100% of Node.js's test suite passes.
61
+
62
+ ### [`node:punycode`](https://nodejs.org/api/punycode.html)
63
+
64
+ 🟢 Fully implemented. 100% of Node.js's test suite passes, _deprecated by Node.js_.
65
+
66
+ ### [`node:querystring`](https://nodejs.org/api/querystring.html)
67
+
68
+ 🟢 Fully implemented. 100% of Node.js's test suite passes.
69
+
70
+ ### [`node:readline`](https://nodejs.org/api/readline.html)
71
+
72
+ 🟢 Fully implemented.
73
+
74
+ ### [`node:stream`](https://nodejs.org/api/stream.html)
75
+
76
+ 🟢 Fully implemented.
77
+
78
+ ### [`node:string_decoder`](https://nodejs.org/api/string_decoder.html)
79
+
80
+ 🟢 Fully implemented. 100% of Node.js's test suite passes.
81
+
82
+ ### [`node:timers`](https://nodejs.org/api/timers.html)
83
+
84
+ 🟢 Recommended to use global `setTimeout`, et. al. instead.
85
+
86
+ ### [`node:tty`](https://nodejs.org/api/tty.html)
87
+
88
+ 🟢 Fully implemented.
89
+
90
+ ### [`node:url`](https://nodejs.org/api/url.html)
91
+
92
+ 🟢 Fully implemented.
93
+
94
+ ### [`node:zlib`](https://nodejs.org/api/zlib.html)
95
+
96
+ 🟢 Fully implemented. 98% of Node.js's test suite passes.
97
+
98
+ ### [`node:async_hooks`](https://nodejs.org/api/async_hooks.html)
99
+
100
+ 🟡 `AsyncLocalStorage`, and `AsyncResource` are implemented. v8 promise hooks are not called, and its usage is [strongly discouraged](https://nodejs.org/docs/latest/api/async_hooks.html#async-hooks).
101
+
102
+ ### [`node:child_process`](https://nodejs.org/api/child_process.html)
103
+
104
+ 🟡 Missing `proc.gid` `proc.uid`. `Stream` class not exported. IPC cannot send socket handles. Node.js ↔ Bun IPC can be used with JSON serialization.
105
+
106
+ ### [`node:cluster`](https://nodejs.org/api/cluster.html)
107
+
108
+ 🟡 Handles and file descriptors cannot be passed between workers, which means load-balancing HTTP requests across processes is only supported on Linux at this time (via `SO_REUSEPORT`). Otherwise, implemented but not battle-tested.
109
+
110
+ ### [`node:crypto`](https://nodejs.org/api/crypto.html)
111
+
112
+ 🟡 Missing `secureHeapUsed` `setEngine` `setFips`
113
+
114
+ ### [`node:domain`](https://nodejs.org/api/domain.html)
115
+
116
+ 🟡 Missing `Domain` `active`
117
+
118
+ ### [`node:http2`](https://nodejs.org/api/http2.html)
119
+
120
+ 🟡 Client & server are implemented (95.25% of gRPC's test suite passes). Missing `options.allowHTTP1`, `options.enableConnectProtocol`, ALTSVC extension, and `http2stream.pushStream`.
121
+
122
+ ### [`node:module`](https://nodejs.org/api/module.html)
123
+
124
+ 🟡 Missing `syncBuiltinESMExports`, `Module#load()`. Overriding `require.cache` is supported for ESM & CJS modules. `module._extensions`, `module._pathCache`, `module._cache` are no-ops. `module.register` is not implemented and we recommend using a [`Bun.plugin`](/runtime/plugins) in the meantime.
125
+
126
+ ### [`node:net`](https://nodejs.org/api/net.html)
127
+
128
+ 🟢 Fully implemented.
129
+
130
+ ### [`node:perf_hooks`](https://nodejs.org/api/perf_hooks.html)
131
+
132
+ 🟡 APIs are implemented, but Node.js test suite does not pass yet for this module.
133
+
134
+ ### [`node:process`](https://nodejs.org/api/process.html)
135
+
136
+ 🟡 See [`process`](#process) Global.
137
+
138
+ ### [`node:sys`](https://nodejs.org/api/util.html)
139
+
140
+ 🟡 See [`node:util`](#node-util).
141
+
142
+ ### [`node:tls`](https://nodejs.org/api/tls.html)
143
+
144
+ 🟡 Missing `tls.createSecurePair`.
145
+
146
+ ### [`node:util`](https://nodejs.org/api/util.html)
147
+
148
+ 🟡 Missing `getCallSite` `getCallSites` `getSystemErrorMap` `getSystemErrorMessage` `transferableAbortSignal` `transferableAbortController`
149
+
150
+ ### [`node:v8`](https://nodejs.org/api/v8.html)
151
+
152
+ 🟡 `writeHeapSnapshot` and `getHeapSnapshot` are implemented. `serialize` and `deserialize` use JavaScriptCore's wire format instead of V8's. Other methods are not implemented. For profiling, use [`bun:jsc`](/project/benchmarking#bunjsc) instead.
153
+
154
+ ### [`node:vm`](https://nodejs.org/api/vm.html)
155
+
156
+ 🟡 Core functionality and ES modules are implemented, including `vm.Script`, `vm.createContext`, `vm.runInContext`, `vm.runInNewContext`, `vm.runInThisContext`, `vm.compileFunction`, `vm.isContext`, `vm.Module`, `vm.SourceTextModule`, `vm.SyntheticModule`, and `importModuleDynamically` support. Options like `timeout` and `breakOnSigint` are fully supported. Missing `vm.measureMemory` and some `cachedData` functionality.
157
+
158
+ ### [`node:wasi`](https://nodejs.org/api/wasi.html)
159
+
160
+ 🟡 Partially implemented.
161
+
162
+ ### [`node:worker_threads`](https://nodejs.org/api/worker_threads.html)
163
+
164
+ 🟡 `Worker` doesn't support the following options: `stdin` `stdout` `stderr` `trackedUnmanagedFds` `resourceLimits`. Missing `markAsUntransferable` `moveMessagePortToContext`.
165
+
166
+ ### [`node:inspector`](https://nodejs.org/api/inspector.html)
167
+
168
+ 🔴 Not implemented.
169
+
170
+ ### [`node:repl`](https://nodejs.org/api/repl.html)
171
+
172
+ 🔴 Not implemented.
173
+
174
+ ### [`node:sqlite`](https://nodejs.org/api/sqlite.html)
175
+
176
+ 🔴 Not implemented.
177
+
178
+ ### [`node:test`](https://nodejs.org/api/test.html)
179
+
180
+ 🟡 Partly implemented. Missing mocks, snapshots, timers. Use [`bun:test`](/test) instead.
181
+
182
+ ### [`node:trace_events`](https://nodejs.org/api/tracing.html)
183
+
184
+ 🔴 Not implemented.
185
+
186
+ ## Node.js globals
187
+
188
+ The table below lists all globals implemented by Node.js and Bun's current compatibility status.
189
+
190
+ ### [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController)
191
+
192
+ 🟢 Fully implemented.
193
+
194
+ ### [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
195
+
196
+ 🟢 Fully implemented.
197
+
198
+ ### [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
199
+
200
+ 🟢 Fully implemented.
201
+
202
+ ### [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer)
203
+
204
+ 🟢 Fully implemented.
205
+
206
+ ### [`ByteLengthQueuingStrategy`](https://developer.mozilla.org/en-US/docs/Web/API/ByteLengthQueuingStrategy)
207
+
208
+ 🟢 Fully implemented.
209
+
210
+ ### [`__dirname`](https://nodejs.org/api/globals.html#__dirname)
211
+
212
+ 🟢 Fully implemented.
213
+
214
+ ### [`__filename`](https://nodejs.org/api/globals.html#__filename)
215
+
216
+ 🟢 Fully implemented.
217
+
218
+ ### [`atob()`](https://developer.mozilla.org/en-US/docs/Web/API/atob)
219
+
220
+ 🟢 Fully implemented.
221
+
222
+ ### [`Atomics`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics)
223
+
224
+ 🟢 Fully implemented.
225
+
226
+ ### [`BroadcastChannel`](https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel)
227
+
228
+ 🟢 Fully implemented.
229
+
230
+ ### [`btoa()`](https://developer.mozilla.org/en-US/docs/Web/API/btoa)
231
+
232
+ 🟢 Fully implemented.
233
+
234
+ ### [`clearImmediate()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/clearImmediate)
235
+
236
+ 🟢 Fully implemented.
237
+
238
+ ### [`clearInterval()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/clearInterval)
239
+
240
+ 🟢 Fully implemented.
241
+
242
+ ### [`clearTimeout()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/clearTimeout)
243
+
244
+ 🟢 Fully implemented.
245
+
246
+ ### [`CompressionStream`](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)
247
+
248
+ 🔴 Not implemented.
249
+
250
+ ### [`console`](https://developer.mozilla.org/en-US/docs/Web/API/console)
251
+
252
+ 🟢 Fully implemented.
253
+
254
+ ### [`CountQueuingStrategy`](https://developer.mozilla.org/en-US/docs/Web/API/CountQueuingStrategy)
255
+
256
+ 🟢 Fully implemented.
257
+
258
+ ### [`Crypto`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto)
259
+
260
+ 🟢 Fully implemented.
261
+
262
+ ### [`SubtleCrypto (crypto)`](https://developer.mozilla.org/en-US/docs/Web/API/crypto)
263
+
264
+ 🟢 Fully implemented.
265
+
266
+ ### [`CryptoKey`](https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey)
267
+
268
+ 🟢 Fully implemented.
269
+
270
+ ### [`CustomEvent`](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent)
271
+
272
+ 🟢 Fully implemented.
273
+
274
+ ### [`DecompressionStream`](https://developer.mozilla.org/en-US/docs/Web/API/DecompressionStream)
275
+
276
+ 🔴 Not implemented.
277
+
278
+ ### [`Event`](https://developer.mozilla.org/en-US/docs/Web/API/Event)
279
+
280
+ 🟢 Fully implemented.
281
+
282
+ ### [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)
283
+
284
+ 🟢 Fully implemented.
285
+
286
+ ### [`exports`](https://nodejs.org/api/globals.html#exports)
287
+
288
+ 🟢 Fully implemented.
289
+
290
+ ### [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/fetch)
291
+
292
+ 🟢 Fully implemented.
293
+
294
+ ### [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
295
+
296
+ 🟢 Fully implemented.
297
+
298
+ ### [`global`](https://nodejs.org/api/globals.html#global)
299
+
300
+ 🟢 Implemented. This is an object containing all objects in the global namespace. It's rarely referenced directly, as its contents are available without an additional prefix, e.g. `__dirname` instead of `global.__dirname`.
301
+
302
+ ### [`globalThis`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis)
303
+
304
+ 🟢 Aliases to `global`.
305
+
306
+ ### [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers)
307
+
308
+ 🟢 Fully implemented.
309
+
310
+ ### [`MessageChannel`](https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel)
311
+
312
+ 🟢 Fully implemented.
313
+
314
+ ### [`MessageEvent`](https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent)
315
+
316
+ 🟢 Fully implemented.
317
+
318
+ ### [`MessagePort`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort)
319
+
320
+ 🟢 Fully implemented.
321
+
322
+ ### [`module`](https://nodejs.org/api/globals.html#module)
323
+
324
+ 🟢 Fully implemented.
325
+
326
+ ### [`PerformanceEntry`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry)
327
+
328
+ 🟢 Fully implemented.
329
+
330
+ ### [`PerformanceMark`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceMark)
331
+
332
+ 🟢 Fully implemented.
333
+
334
+ ### [`PerformanceMeasure`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceMeasure)
335
+
336
+ 🟢 Fully implemented.
337
+
338
+ ### [`PerformanceObserver`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver)
339
+
340
+ 🟢 Fully implemented.
341
+
342
+ ### [`PerformanceObserverEntryList`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserverEntryList)
343
+
344
+ 🟢 Fully implemented.
345
+
346
+ ### [`PerformanceResourceTiming`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming)
347
+
348
+ 🟢 Fully implemented.
349
+
350
+ ### [`performance`](https://developer.mozilla.org/en-US/docs/Web/API/performance)
351
+
352
+ 🟢 Fully implemented.
353
+
354
+ ### [`process`](https://nodejs.org/api/process.html)
355
+
356
+ 🟡 Mostly implemented. `process.binding` (internal Node.js bindings some packages rely on) is partially implemented. `process.title` is currently a no-op on macOS & Linux. `getActiveResourcesInfo` `setActiveResourcesInfo`, `getActiveResources` and `setSourceMapsEnabled` are stubs. Newer APIs like `process.loadEnvFile` and `process.getBuiltinModule` are not implemented yet.
357
+
358
+ ### [`queueMicrotask()`](https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask)
359
+
360
+ 🟢 Fully implemented.
361
+
362
+ ### [`ReadableByteStreamController`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableByteStreamController)
363
+
364
+ 🟢 Fully implemented.
365
+
366
+ ### [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream)
367
+
368
+ 🟢 Fully implemented.
369
+
370
+ ### [`ReadableStreamBYOBReader`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader)
371
+
372
+ 🟢 Fully implemented.
373
+
374
+ ### [`ReadableStreamBYOBRequest`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBRequest)
375
+
376
+ 🟢 Fully implemented.
377
+
378
+ ### [`ReadableStreamDefaultController`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultController)
379
+
380
+ 🟢 Fully implemented.
381
+
382
+ ### [`ReadableStreamDefaultReader`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader)
383
+
384
+ 🟢 Fully implemented.
385
+
386
+ ### [`require()`](https://nodejs.org/api/globals.html#require)
387
+
388
+ 🟢 Fully implemented, including [`require.main`](https://nodejs.org/api/modules.html#requiremain), [`require.cache`](https://nodejs.org/api/modules.html#requirecache), [`require.resolve`](https://nodejs.org/api/modules.html#requireresolverequest-options).
389
+
390
+ ### [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
391
+
392
+ 🟢 Fully implemented.
393
+
394
+ ### [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
395
+
396
+ 🟢 Fully implemented.
397
+
398
+ ### [`setImmediate()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate)
399
+
400
+ 🟢 Fully implemented.
401
+
402
+ ### [`setInterval()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/setInterval)
403
+
404
+ 🟢 Fully implemented.
405
+
406
+ ### [`setTimeout()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout)
407
+
408
+ 🟢 Fully implemented.
409
+
410
+ ### [`structuredClone()`](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone)
411
+
412
+ 🟢 Fully implemented.
413
+
414
+ ### [`SubtleCrypto`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto)
415
+
416
+ 🟢 Fully implemented.
417
+
418
+ ### [`DOMException`](https://developer.mozilla.org/en-US/docs/Web/API/DOMException)
419
+
420
+ 🟢 Fully implemented.
421
+
422
+ ### [`TextDecoder`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder)
423
+
424
+ 🟢 Fully implemented.
425
+
426
+ ### [`TextDecoderStream`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoderStream)
427
+
428
+ 🟢 Fully implemented.
429
+
430
+ ### [`TextEncoder`](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder)
431
+
432
+ 🟢 Fully implemented.
433
+
434
+ ### [`TextEncoderStream`](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoderStream)
435
+
436
+ 🟢 Fully implemented.
437
+
438
+ ### [`TransformStream`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream)
439
+
440
+ 🟢 Fully implemented.
441
+
442
+ ### [`TransformStreamDefaultController`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStreamDefaultController)
443
+
444
+ 🟢 Fully implemented.
445
+
446
+ ### [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL)
447
+
448
+ 🟢 Fully implemented.
449
+
450
+ ### [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
451
+
452
+ 🟢 Fully implemented.
453
+
454
+ ### [`WebAssembly`](https://nodejs.org/api/globals.html#webassembly)
455
+
456
+ 🟢 Fully implemented.
457
+
458
+ ### [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream)
459
+
460
+ 🟢 Fully implemented.
461
+
462
+ ### [`WritableStreamDefaultController`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultController)
463
+
464
+ 🟢 Fully implemented.
465
+
466
+ ### [`WritableStreamDefaultWriter`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter)
467
+
468
+ 🟢 Fully implemented.