deno/ext/node/polyfills
Bartek Iwańczuk 1b6736d3f9
Some checks are pending
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
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 / 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 / test release windows-x86_64 (push) Blocked by required conditions
ci / build wasm32 (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions
fix(ext/node): node:buffer validates INSPECT_MAX_BYTES (#29469)
Co-authored-by: David Sherret <dsherret@users.noreply.github.com>
2025-05-27 23:31:35 +00:00
..
_fs fix(ext/node): use primordials in ext/node/polyfills/_fs/_fs_truncate.ts (#29422) 2025-05-25 23:49:39 +02:00
_process fix: process.stdin.pause() (#29330) 2025-05-17 18:46:26 +05:30
_util fix(ext/node): fix deepStrictEqual(-0, 0) (#29060) 2025-04-27 22:19:36 +09:00
assert chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
dns chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
fs chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
inspector chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
internal fix(ext/node): node:buffer validates INSPECT_MAX_BYTES (#29469) 2025-05-27 23:31:35 +00:00
internal_binding fix(ext/node): prevent stdin double read (#29353) 2025-05-17 17:17:39 +00:00
path fix(ext/node): use primordials in ext/node/polyfills/path/separator.ts (#28669) 2025-04-08 10:42:58 +09:00
readline chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
stream fix(ext/node): upgrade node:stream (#28855) 2025-04-14 21:35:34 +05:30
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 feat: use a single 'performance' global (#29323) 2025-05-17 00:11:11 +02:00
02_init.js feat: use a single 'performance' global (#29323) 2025-05-17 00:11:11 +02: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 chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_global.d.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_http_agent.mjs chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_http_common.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_http_outgoing.ts fix(ext/node): upgrade node:stream (#28855) 2025-04-14 21:35:34 +05:30
_http_server.ts fix(ext/node): correct STATUS_CODES strings (#28489) 2025-03-13 14:21:08 -04:00
_next_tick.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_readline.d.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_readline.mjs chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00: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.ts fix(ext/node): TLS server unref (#29279) 2025-05-13 21:38:41 +05:30
_utils.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
_zlib.mjs fix(ext/node): expose brotli stream APIs (#27943) 2025-02-04 07:47:02 +05:30
_zlib_binding.mjs fix(ext/node): verbose zlib error messages (#28831) 2025-04-11 17:17:32 +05:30
assert.ts fix(ext/node): export CallTracker as named export (#29271) 2025-05-13 10:15:48 +09:00
assertion_error.ts fix: add stackTraceLimit to ErrorConstructor interface and removed ErrorWithStackTraceLimit interface (#28539) 2025-03-18 09:56:39 -04:00
async_hooks.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
buffer.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
child_process.ts refactor(ext/node): use Promise.withResolvers (#28917) 2025-04-15 17:33:53 -04: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): implement crypto.hash (#27858) 2025-01-29 20:49:43 +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): Fix dns.lookup when promisified with options.all (#29167) 2025-05-06 09:16:00 +05:30
domain.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
events.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
fs.ts fix(ext/node): add fchown and fchownSync to node:fs (#29408) 2025-05-23 15:00:39 +09:00
http.ts fix(ext/node): handle null ssl options in node:https (#29365) 2025-05-19 07:55:15 +02:00
http2.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00: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: process.stdin.pause() (#29330) 2025-05-17 18:46:26 +05:30
os.ts refactor: add 'deno_os' crate (#27655) 2025-01-14 17:29:36 +01:00
path.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
perf_hooks.js feat: use a single 'performance' global (#29323) 2025-05-17 00:11:11 +02:00
process.ts fix(compile): init dummy stdin after debug env is initialized (#29144) 2025-05-27 12:10:20 +05:30
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 fix(ext/node): expose sqlite changeset constants (#27992) 2025-02-06 13:08:40 +05:30
stream.ts fix(ext/node): upgrade node:stream (#28855) 2025-04-14 21:35:34 +05:30
string_decoder.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
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 chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
url.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
util.ts refactor(ext/node): use Promise.withResolvers (#28917) 2025-04-15 17:33:53 -04:00
v8.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00: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): emit 'worker' event when a new worker thread is created (#29345) 2025-05-17 12:35:05 +05:30
zlib.ts fix(ext/node): expose brotli stream APIs (#27943) 2025-02-04 07:47:02 +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.