deno/ext/node/polyfills
2025-05-09 14:55:28 +00:00
..
_fs fix(ext/node): use primordials in ext/node/polyfills/_fs/_fs_mkdtemp.ts (#29072) 2025-05-07 16:00:26 +02:00
_process fix(ext/node): getColorDepth for writable stdio streams (#29176) 2025-05-06 21:42:14 +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): add assert.CallTracker (#29226) 2025-05-09 14:55:28 +00:00
internal_binding fix(ext/node): dgram multicast group membership (#29207) 2025-05-08 22:07:40 +05:30
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 fix(ext/node): upgrade node:stream (#28855) 2025-04-14 21:35:34 +05:30
02_init.js chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +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 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): npm:mqtt compatibility (#27792) 2025-01-27 11:47:32 +09:00
_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): add assert.CallTracker (#29226) 2025-05-09 14:55:28 +00: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 writev method to FileHandle (#27563) 2025-01-14 18:01:14 +09:00
http.ts fix(node:http): ServerResponse.req not set (#29211) 2025-05-08 18:42:04 +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(ext/node): better dns.lookup compatibility (#27936) 2025-04-02 11:38:07 +09:00
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.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
process.ts chore: make node test-process-cpuUsage pass (#28912) 2025-04-16 08:28:18 +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 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(node/test): basic support for t.skip and t.todo (#29222) 2025-05-09 01:40:16 +02: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 chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
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.