deno/ext/node/polyfills
gitstart-app[bot] b5df174549 feat(node): implement proper HTTP request destruction and stream.finished() compatibility
- Add connection termination error detection in Rust HTTP ops layer
  - Implement client-server request registry for error propagation
  - Fix FakeSocket destroy behavior with proper ECONNRESET emission
  - Enhance IncomingMessageForServer with proper destroy() method
  - Add stream state management for finished() compatibility
  - Enable parallel/test-stream-finished.js in Node.js compatibility suite

  Fixes failing Node.js compatibility test by implementing proper request
  destruction patterns that emit ECONNRESET errors when server calls
  req.destroy(), matching Node.js behavior.
2025-09-03 06:23:35 +00:00
..
_fs fix(node): regression where Node fs APIs required elevated permissions on Windows (#30535) 2025-08-27 09:29:44 -04:00
_process fix: upgrade @node/types to 24 (#30343) 2025-08-07 16:08:47 +00: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): Readable adapter cancel semantics (#30526) 2025-09-01 09:29:06 +00:00
internal_binding fix(ext/node): support JS underlying stream in TLS (#30465) 2025-08-28 17:56:17 +05:30
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 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 feat(node): implement proper HTTP request destruction and stream.finished() compatibility 2025-09-03 06:23:35 +00:00
_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 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 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): 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 feat(node API): add fs.glob, fs.globSync, fs.promises.glob (#28972) 2025-07-01 11:35:45 +02:00
http.ts feat(node): implement proper HTTP request destruction and stream.finished() compatibility 2025-09-03 06:23:35 +00: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 fix(ext/node): export StatementSync from node:sqlite (#29563) 2025-06-02 11:34:41 +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.