Files
bun.sh/docs/runtime/nodejs-apis.md
Colin McDonnell 9b6913e1a6 More/better docs for JSX, utils, binary data, streams, hashing, bun test, Bun.serve (#3005)
* WIP

* Updates

* Document deepEquals

* WIP

* Update typeS

* Update TLS docs for Bun.serve

* Update types for tls

* Draft binary data page. Add Streams page.

* Update test runner docs

* Add hashing, flesh out utils

* Grammar

* Update types

* Fix

* Add import.meta docs

* Tee
2023-05-29 11:49:51 -07:00

20 KiB

Bun aims for complete Node.js API compatibility. Most npm packages intended for Node.js environments will work with Bun out of the box; the best way to know for certain is to try it.

This page is updated regularly to reflect compatibility status of the latest version of Bun.

Built-in modules

{% block className="ScrollFrame" %} {% table %}

  • Module
  • Status
  • Notes

  • {% anchor id="node_assert" %} node:assert {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_async_hooks" %} node:async_hooks {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_buffer" %} node:buffer {% /anchor %}
  • 🟡
  • Incomplete implementation of base64 and base64url encodings.

  • {% anchor id="node_child_process" %} node:child_process {% /anchor %}
  • 🟡
  • Missing IPC, Stream stdio, proc.gid, proc.uid, advanced serialization.

  • {% anchor id="node_cluster" %} node:cluster {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_console" %} node:console {% /anchor %}
  • 🟢
  • Recommended to use console global instead

  • {% anchor id="node_crypto" %} node:crypto {% /anchor %}
  • 🟡
  • Missing crypto.Certificate crypto.ECDH crypto.KeyObject crypto.X509Certificate crypto.checkPrime{Sync} crypto.createPrivateKey crypto.createPublicKey crypto.createSecretKey crypto.diffieHellman crypto.generateKey{Sync} crypto.generateKeyPair{Sync} crypto.generatePrime{Sync} crypto.getCipherInfo crypto.getCurves crypto.{get|set}Fips crypto.hkdf crypto.hkdfSync crypto.randomInt crypto.secureHeapUsed crypto.setEngine crypto.sign crypto.verify

  • {% anchor id="node_dgram" %} node:dgram {% /anchor %}
  • 🔴
  • Not implemented.


  • {% anchor id="node_dns" %} node:dns {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_domain" %} node:domain {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_events" %} node:events {% /anchor %}
  • 🟡
  • Missing EventEmitterAsyncResource. EventEmitter is missing {get}set}MaxListeners usingDomains init.

  • {% anchor id="node_fs" %} node:fs {% /anchor %}
  • 🟡
  • Missing fs.fdatasync{Sync} fs.opendir{Sync} fs.readv{Sync} fs.{watch|watchFile|unwatchFile} fs.writev{Sync}.

  • {% anchor id="node_http" %} node:http {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_http2" %} node:http2 {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_https" %} node:https {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_inspector" %} node:inspector {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_module" %} node:module {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_net" %} node:net {% /anchor %}
  • 🟡
  • Missing net.createServer net.{get|set}DefaultAutoSelectFamily net.SocketAddress net.BlockList.

  • {% anchor id="node_os" %} node:os {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_path" %} node:path {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_perf_hooks" %} node:perf_hooks {% /anchor %}
  • 🟡
  • Only perf_hooks.performance.now() and perf_hooks.performance.timeOrigin are implemented. Recommended to use performance global instead of perf_hooks.performance.

  • {% anchor id="node_process" %} node:process {% /anchor %}
  • 🟡
  • See Globals > process.

  • {% anchor id="node_punycode" %} node:punycode {% /anchor %}
  • 🟢
  • Fully implemented. Deprecated by Node.js.

  • {% anchor id="node_querystring" %} node:querystring {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_readline" %} node:readline {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_repl" %} node:repl {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_stream" %} node:stream {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_string_decoder" %} node:string_decoder {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_sys" %} node:sys {% /anchor %}
  • 🟡
  • See node:util.

  • {% anchor id="node_timers" %} node:timers {% /anchor %}
  • 🟢
  • Recommended to use global setTimeout, et. al. instead.

  • {% anchor id="node_tls" %} node:tls {% /anchor %}
  • 🟡
  • Missing tls.Server tls.createServer tls.createSecurePair tls.checkServerIdentity tls.rootCertificates

  • {% anchor id="node_trace_events" %} node:trace_events {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_tty" %} node:tty {% /anchor %}
  • 🟡
  • Missing tty.ReadStream and tty.WriteStream.

  • {% anchor id="node_url" %} node:url {% /anchor %}
  • 🟡
  • Missing url.domainTo{ASCII|Unicode} url.urlToHttpOptions. Recommended to use URL and URLSearchParams globals instead.

  • {% anchor id="node_util" %} node:util {% /anchor %}
  • 🟡
  • Missing util.MIMEParams util.MIMEType util.formatWithOptions() util.getSystemErrorMap() util.getSystemErrorName() util.parseArgs() util.stripVTControlCharacters() util.toUSVString() util.transferableAbortController() util.transferableAbortSignal().

  • {% anchor id="node_v8" %} node:v8 {% /anchor %}
  • 🔴
  • Not implemented or planned. For profiling, use bun:jsc instead.

  • {% anchor id="node_vm" %} node:vm {% /anchor %}
  • 🟡
  • Partially implemented.

  • {% anchor id="node_wasi" %} node:wasi {% /anchor %}
  • 🟡
  • Partially implemented.

  • {% anchor id="node_worker_threads" %} node:worker_threads {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_zlib" %} node:zlib {% /anchor %}
  • 🟡
  • Missing zlib.brotli*

{% /table %} {% /block %}

Globals

The table below lists all globals implemented by Node.js and Bun's current compatibility status.

{% table %}


  • {% anchor id="node_abortcontroller" %} AbortController {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_abortsignal" %} AbortSignal {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_blob" %} Blob {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_buffer" %} Buffer {% /anchor %}
  • 🟡
  • Incomplete implementation of base64 and base64url encodings.


  • {% anchor id="node_dirname" %} __dirname {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_filename" %} __filename {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_atob" %} atob() {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_broadcastchannel" %} BroadcastChannel {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_btoa" %} btoa() {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_clearimmediate" %} clearImmediate() {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_clearinterval" %} clearInterval() {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_cleartimeout" %} clearTimeout() {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_compressionstream" %} CompressionStream {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_console" %} console {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_countqueuingstrategy" %} CountQueuingStrategy {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_crypto" %} Crypto {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_crypto" %} crypto {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_cryptokey" %} CryptoKey {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_customevent" %} CustomEvent {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_decompressionstream" %} DecompressionStream {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_event" %} Event {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_eventtarget" %} EventTarget {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_exports" %} exports {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_fetch" %} fetch {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_formdata" %} FormData {% /anchor %}
  • 🟢
  • Fully implemented. Added in Bun 0.5.7.

  • {% anchor id="node_global" %} global {% /anchor %}
  • 🟢
  • 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.

  • {% anchor id="node_globalthis" %} globalThis {% /anchor %}
  • 🟢
  • Aliases to global.

  • {% anchor id="node_headers" %} Headers {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_messagechannel" %} MessageChannel {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_messageevent" %} MessageEvent {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_messageport" %} MessagePort {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_module" %} module {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_performanceentry" %} PerformanceEntry {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_performancemark" %} PerformanceMark {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_performancemeasure" %} PerformanceMeasure {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_performanceobserver" %} PerformanceObserver {% /anchor %}
  • 🔴
  • Not implemented.



  • {% anchor id="node_performance" %} performance {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_process" %} process {% /anchor %}
  • 🟡
  • Missing process.allowedNodeEnvironmentFlags process.channel() process.connected process.constrainedMemory() process.cpuUsage() process.debugPort process.disconnect() process.{get|set}ActiveResourcesInfo() process.{get|set}{uid|gid|egid|euid|groups}() process.hasUncaughtExceptionCaptureCallback process.initGroups() process.kill() process.listenerCount process.memoryUsage() process.report process.resourceUsage() process.setSourceMapsEnabled() process.send().

  • {% anchor id="node_queuemicrotask" %} queueMicrotask() {% /anchor %}
  • 🟢
  • Fully implemented.


  • {% anchor id="node_readablestream" %} ReadableStream {% /anchor %}
  • 🟢
  • Fully implemented.





  • {% anchor id="node_require" %} require() {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_response" %} Response {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_request" %} Request {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_setimmediate" %} setImmediate() {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_setinterval" %} setInterval() {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_settimeout" %} setTimeout() {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_structuredclone" %} structuredClone() {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_subtlecrypto" %} SubtleCrypto {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_domexception" %} DOMException {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_textdecoder" %} TextDecoder {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_textdecoderstream" %} TextDecoderStream {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_textencoder" %} TextEncoder {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_textencoderstream" %} TextEncoderStream {% /anchor %}
  • 🔴
  • Not implemented.

  • {% anchor id="node_transformstream" %} TransformStream {% /anchor %}
  • 🟢
  • Fully implemented.


  • {% anchor id="node_url" %} URL {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_urlsearchparams" %} URLSearchParams {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_webassembly" %} WebAssembly {% /anchor %}
  • 🟢
  • Fully implemented.

  • {% anchor id="node_writablestream" %} WritableStream {% /anchor %}
  • 🟢
  • Fully implemented.


{% /table %}