deno/ext/node/polyfills
snek 4772778107
Some checks are pending
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / build libs (push) Blocked by required conditions
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions
refactor: http upgrade internals (#30612)
clean up some outdated code and implement a few performance
improvements. most notably, the response from `upgradeWebSocket` is now
actually used as a normal response.

a followup pr will rework raw upgrades to a greater extent
2025-09-19 09:33:32 +02:00
..
_fs fix(ext/node): fs.statfsSync and fs.statfs compatibility (#30662) 2025-09-18 16:03:30 +02:00
_process fix(ext/node): handle falsy values enumerability in process.env (#30708) 2025-09-15 11:59:51 +02:00
_util fix(ext/node): add lchmod, lchmod promise, lchmodSync to node:fs (#29833) 2025-06-26 15:46:07 +09:00
assert chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
deps feat(node API): add fs.glob, fs.globSync, fs.promises.glob (#28972) 2025-07-01 11:35:45 +02:00
dns chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
fs feat(node API): add fs.glob, fs.globSync, fs.promises.glob (#28972) 2025-07-01 11:35:45 +02:00
inspector chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
internal fix(ext/node): validate fs.read on empty buffer (#30706) 2025-09-16 11:16:17 +02:00
internal_binding fix(ext/node): accept ArrayBuffer on crypto.timingSafeEqual (#30773) 2025-09-18 16:51:56 +02:00
path fix(ext/node): path.relative compatibility (#30566) 2025-09-01 11:44:51 +02:00
readline chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
stream fix(ext/node): improve input validations of stream/consumers (#29880) 2025-06-25 16:10:57 +09:00
timers chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
util chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
00_globals.js chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
01_require.js fix(node): regression where Node fs APIs required elevated permissions on Windows (#30535) 2025-08-27 09:29:44 -04:00
02_init.js fix(ext/node): worker_threads handles basic require calls (#30279) 2025-08-02 11:27:06 +00:00
_brotli.js fix(ext/node): fix async variant of brotliDecompress (#27815) 2025-01-27 09:13:47 +05:30
_events.d.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_events.mjs fix(node): use primordials more consistently in _events.mjs (#29930) 2025-06-28 19:03:21 +02:00
_global.d.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_http_agent.mjs fix(ext/node): fix hang induced by maxSockets bounds (#30622) 2025-09-05 21:43:51 +05:30
_http_common.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_http_outgoing.ts fix(ext/node): enable Buffer pool for strings (#29592) 2025-06-05 12:04:32 +09:00
_http_server.ts fix(ext/node): correct STATUS_CODES strings (#28489) 2025-03-13 14:21:08 -04:00
_next_tick.ts feat(node): implement async hooks for nextTick TickObject tracking (#30578) 2025-09-03 10:44:10 +02:00
_readline.d.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_readline.mjs fix(ext/node): createInterface doesn't require env permission (#29472) 2025-05-28 11:59:26 +02:00
_readline_shared_types.d.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_stream.d.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_tls_common.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_tls_wrap.js fix(ext/node): support JS underlying stream in TLS (#30465) 2025-08-28 17:56:17 +05:30
_utils.ts fix(ext/node): accept base64url encoding on StringDecoder (#30366) 2025-08-10 18:49:14 +05:30
_zlib_binding.mjs fix(ext/node): use Zlib base for brotli handles (#30112) 2025-07-28 10:11:59 +05:30
assert.ts fix(ext/node): improve assert.fail (#29850) 2025-06-25 10:26:33 +09:00
assertion_error.ts fix(ext/node): improve comparison of faked objects in deepStrictEqual (#29819) 2025-06-20 23:33:18 +09:00
async_hooks.ts feat(node): implement async hooks for nextTick TickObject tracking (#30578) 2025-09-03 10:44:10 +02:00
buffer.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
child_process.ts fix(ext/node): ignore Node.js' --experimental-* flags when spawning child process (#26351) 2025-09-04 12:18:51 +00:00
cluster.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
console.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
constants.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
crypto.ts fix(ext/node): accept base64url encoding on StringDecoder (#30366) 2025-08-10 18:49:14 +05:30
dgram.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
diagnostics_channel.js chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
dns.ts fix(ext/node): improve getaddrinfo compatibility (#29501) 2025-06-02 11:34:36 +09:00
domain.ts fix(ext/node): update interaction between event emitters and domains (#29632) 2025-06-09 12:06:43 +09:00
events.ts fix(ext/node): add events getMaxListeners (#29636) 2025-06-08 04:07:03 +00:00
fs.ts fix(ext/node): fs.statfsSync and fs.statfs compatibility (#30662) 2025-09-18 16:03:30 +02:00
http.ts refactor: http upgrade internals (#30612) 2025-09-19 09:33:32 +02:00
http2.ts fix(ext/http2): fix oob buffer reads in http2 requests (#29969) 2025-07-02 09:28:50 -07:00
https.ts fix(ext/node): Support mTLS connections node compatibility (#28937) 2025-05-06 14:25:18 +05:30
inspector.js chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
net.ts fix(ext/node): support JS underlying stream in TLS (#30465) 2025-08-28 17:56:17 +05:30
os.ts fix(ext/node): os.setPriority and os.getPriority compatibility (#30383) 2025-08-18 19:07:28 +02:00
path.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
perf_hooks.js fix(ext/node): add back perf_hooks.markResourceTiming (#29562) 2025-06-02 17:53:38 +05:30
process.ts fix(ext/node): add process._rawDebug (#30141) 2025-07-18 19:29:31 +02:00
punycode.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
querystring.js fix(ext/node): querystring fallback to default decoder (#28838) 2025-04-14 15:17:28 +05:30
readline.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
README.md chore: move tools/node_compat to tests/node_compat/runner (#23025) 2024-04-03 09:24:55 +11:00
repl.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
sqlite.ts feat(ext/node): add sqlite-type symbol for DatabaseSync (#30511) 2025-09-08 23:45:39 +00:00
stream.ts fix(ext/node): export promises from stream (#30427) 2025-08-17 18:56:29 +05:30
string_decoder.ts fix(ext/node): accept base64url encoding on StringDecoder (#30366) 2025-08-10 18:49:14 +05:30
sys.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
testing.ts fix(ext/node): include assert.ok in node:test (#29383) 2025-05-20 04:05:19 +00:00
timers.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
tls.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
trace_events.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
tty.js test(ext/node): expose TTY class from tty_wrap for testing (#29862) 2025-06-25 12:54:35 +09:00
url.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
util.ts fix: upgrade @node/types to 24 (#30343) 2025-08-07 16:08:47 +00:00
v8.ts fix(ext/node): support DEP0005 deprecation warning (#29530) 2025-06-04 12:25:32 +09:00
vm.js chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
wasi.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
worker_threads.ts fix(ext/node): worker_threads handles basic require calls (#30279) 2025-08-02 11:27:06 +00:00
zlib.js fix(ext/node): use Zlib base for brotli handles (#30112) 2025-07-28 10:11:59 +05:30

Deno Node.js compatibility

This module is meant to have a compatibility layer for the Node.js standard library.

Warning: Any function of this module should not be referred anywhere in the Deno standard library as it's a compatibility module.

Supported modules

  • assert
  • assert/strict partly
  • async_hooks partly
  • buffer
  • child_process partly
  • cluster partly
  • console partly
  • constants partly
  • crypto partly
  • dgram partly
  • diagnostics_channel partly
  • dns partly
  • events
  • fs partly
  • fs/promises partly
  • http partly
  • http2
  • https partly
  • inspector partly
  • module
  • net
  • os partly
  • path
  • path/posix
  • path/win32
  • perf_hooks
  • process partly
  • punycode
  • querystring
  • readline
  • repl partly
  • stream
  • stream/promises
  • stream/web partly
  • string_decoder
  • sys
  • timers
  • timers/promises
  • tls
  • trace_events
  • tty partly
  • url
  • util partly
  • util/types partly
  • v8
  • vm partly
  • wasi
  • webcrypto
  • worker_threads
  • zlib
  • node globals partly

Deprecated

These modules are deprecated in Node.js and will probably not be polyfilled:

  • domain
  • freelist

Experimental

These modules are experimental in Node.js and will not be polyfilled until they are stable:

  • diagnostics_channel
  • async_hooks
  • policies
  • trace_events
  • wasi
  • webcrypto

CommonJS modules loading

createRequire(...) is provided to create a require function for loading CJS modules. It also sets supported globals.

import { createRequire } from "node:module";

const require = createRequire(import.meta.url);
// Loads native module polyfill.
const path = require("path");
// Loads extensionless module.
const cjsModule = require("./my_mod");
// Visits node_modules.
const leftPad = require("left-pad");

Contributing

Setting up the test runner and running tests

See tests/node_compat/runner/README.md.

Best practices

When converting from promise-based to callback-based APIs, the most obvious way is like this:

promise.then((value) => callback(null, value)).catch(callback);

This has a subtle bug - if the callback throws an error, the catch statement will also catch that error, and the callback will be called twice. The correct way to do it is like this:

promise.then((value) => callback(null, value), callback);

The second parameter of then can also be used to catch errors, but only errors from the existing promise, not the new one created by the callback.

If the Deno equivalent is actually synchronous, there's a similar problem with try/catch statements:

try {
  const value = process();
  callback(null, value);
} catch (err) {
  callback(err);
}

Since the callback is called within the try block, any errors from it will be caught and call the callback again.

The correct way to do it is like this:

let err, value;
try {
  value = process();
} catch (e) {
  err = e;
}
if (err) {
  callback(err); // Make sure arguments.length === 1
} else {
  callback(null, value);
}

It's not as clean, but prevents the callback being called twice.

Remaining Tests

Node compatibility can be measured by how many native Node tests pass. If you'd like to know what you can work on, check out the list of Node tests remaining here.