Skip to main content
On this page

Deno 为多个内置的 Node.js 模块和全局变量提供了填充。

探索内置 Node API

Node 兼容性是一个正在进行的项目——帮助我们识别缺口,并告诉我们 您需要哪些模块,通过 在 GitHub 上开一个问题

Fully supported modules (22/44) Jump to heading

node:assert Jump to heading

node:buffer Jump to heading

node:child_process Jump to heading

node:console Jump to heading

node:crypto Jump to heading

Certificate: The methods are non-functional stubs.

generateKeyPair: The x448 option is not supported.

generatePrime: The safe, add and rem option is not supported.

KeyObject: The following are non-functional stubs:

  • from
  • symmetricKeySize
  • equals

publicDecrypt: This symbol is a non-functional stub.

secureHeapUsed: This symbol is a non-functional stub.

setEngine: This symbol is a non-functional stub.

ECDH: The convertKey method is a non-functional sub.

Sign: The sign and verify methods are not supported with non BinaryLike input.

node:diagnostics_channel Jump to heading

node:events Jump to heading

node:fs Jump to heading

writeFile: Missing utf16le, latin1 and ucs2 encoding.

writeFileSync: Missing utf16le, latin1 and ucs2 encoding.

node:fs/promises Jump to heading

lchmod: The lchmod implementation is a not implemented.

node:module Jump to heading

Module: The register method is a non-functional stub.

node:os Jump to heading

node:path Jump to heading

node:punycode Jump to heading

node:querystring Jump to heading

node:readline Jump to heading

node:sqlite Jump to heading

This module has been added in Deno v2.2.

node:stream Jump to heading

node:string_decoder Jump to heading

node:test Jump to heading

node:timers Jump to heading

node:tty Jump to heading

node:url Jump to heading

Partially supported modules (16/44) Jump to heading

node:async_hooks Jump to heading

AsyncResource: The AsyncResource implementation is a non-functional stub.

executionAsyncId: The executionAsyncId implementation is a non-functional stub.

createHook: The createHook implementation is a non-functional stub.

node:dgram Jump to heading

Socket: The following methods are non-functional stubs:

  • addMembership
  • addSourceSpecificMembership
  • dropMembership
  • dropSourceSpecificMembership
  • setBroadcast
  • setMulticastInterface
  • setMulticastLoopback
  • setMulticastTtl
  • setTtl

node:dns Jump to heading

resolve: The ttl option is not supported.

resolve4: The ttl option is not supported.

resolve6: The ttl option is not supported.

resolveCname: The ttl option is not supported.

resolveCaa: The ttl option is not supported.

resolveMx: The ttl option is not supported.

resolveNaptr: The ttl option is not supported.

resolveNs: The ttl option is not supported.

resolvePtr: The ttl option is not supported.

resolveSoa: The ttl option is not supported.

resolveSrv: The ttl option is not supported.

resolveTxt: The ttl option is not supported.

resolveAny: The ttl option is not supported.

node:http Jump to heading

RequestOptions: Option createConnection is not supported.

ClientRequestArgs: Option createConnection is not supported.

ClientRequest: Constructor option createConnection is not supported.

request: Constructor option createConnection is not supported.

get: Constructor option createConnection is not supported.

node:http2 Jump to heading

Http2Session: The following methods are non-functional stubs:

  • setLocalWindowSize
  • ping
  • localSettings
  • remoteSettings
  • settings
  • ref
  • unref

ServerHttp2Session: All methods are non-functional stubs.

Http2Stream: The following methods are non-functional stubs:

  • aborted
  • bufferSize
  • endAfterHeaders
  • id
  • pending
  • priority
  • rstCode
  • sentHeaders
  • sentInfoHeaders
  • sentTrailers
  • state

ClientHttp2Stream: All methods are non-functional stubs.

getDefaultSettings: This function is a non-functional stub.

getPackedSettings: This function is a non-functional stub.

getUnpackedSettings: This function is a non-functional stub.

node:https Jump to heading

Server: The cert and key options do not support an array input.

node:inspector Jump to heading

console is supported. Other APIs are non-functional stubs.

node:net Jump to heading

Socket: The fd option is not supported.

node:perf_hooks Jump to heading

performance: The eventLoopUtilization method is a non-functional stub. The timerify method is not implemented.

monitorEventLoopDelay: This symbol is not implemented.

node:process Jump to heading

The multipleResolves and worker events are not supported.

node:tls Jump to heading

createSecurePair: This symbol is currently not supported.

node:util Jump to heading

transferableAbortSignal: This symbol is currently not supported.

transferableAbortController: This symbol is currently not supported.

MIMEParams: This symbol is currently not supported.

MIMEType: This symbol is currently not supported.

getSystemErrorMap: This symbol is currently not supported.

node:v8 Jump to heading

cachedDataVersionTag and getHeapStatistics, serialize and deserialize are supported. setFlagsFromStrings is a noop. Other APIs are not supported and will throw and error.

setFlagsFromStrings: This function is a noop.

node:vm Jump to heading

measureMemory: This is a non-functional stub.

compile: The importModuleDynamically parameter is not supported.

createContext: The importModuleDynamically parameter is not supported.

Script: The importModuleDynamically parameter is not supported. The runInContext method does not support break on SIGINT.

node:worker_threads Jump to heading

parentPort: The emit method is not supported. The removeAllListeners method is not supported.

markAsUntransferable: This symbol is not supported.

moveMessagePortToContext: This symbol is not supported.

receiveMessageOnPort: This symbol is not supported.

Worker: The getHeapSnapshot method is not supported.

node:zlib Jump to heading

Options: This class is not supported.

BrotliOptions: This class is not supported.

BrotliCompress: This class is not supported.

BrotliDecompress: This class is not supported.

ZlibBase: This class is not supported.

Unsupported modules (6/44) Jump to heading

node:cluster Jump to heading

All exports are non-functional stubs.

All symbols: This symbol is a non-functional stub.

node:domain Jump to heading

All exports are non-functional stubs. This is a deprecated Node module.

All symbols: This symbol is a non-functional stub.

node:repl Jump to heading

All symbols are not supported.

All symbols: This symbol is not supported.

node:sea Jump to heading

All symbols are not supported.

All symbols: This symbol is not supported.

node:trace_events Jump to heading

All exports are non-functional stubs.

All symbols: This symbol is a non-functional stub.

node:wasi Jump to heading

All exports are non-functional stubs.

All symbols: This symbol is a non-functional stub.

全局变量 Jump to heading

这是 Deno 支持的 Node 全局变量列表。这些全局变量仅在 npm 包范围内可用。在您自己的代码中,您可以通过从相关的 node: 模块导入它们来使用它们。

__dirname__filename Jump to heading

__dirname__filename 是 CommonJS 全局变量。它们在 npm 包作用域内的 CommonJS 模块中可用,但在 ES 模块中未定义。在您自己的 ES 模块中,请改用 import.meta.dirnameimport.meta.filename,它们为当前模块提供相同的值。

模块说明 Jump to heading

node:worker_threads Jump to heading

Deno 2.7 显著提升了 node:worker_threads 的兼容性:

  • stdoutstderr 流会从 worker 正确转发到父进程。
  • worker.terminate() 现在会以正确的退出码解析。
  • 支持 workerDataexecArgvthreadName 选项。
  • 已实现 worker.performance.eventLoopUtilization()worker.cpuUsage()
  • 来自 worker 线程的 BroadcastChannel 能正确进行 ref/unref。

node:child_process Jump to heading

Deno 2.7 提升了 node:child_process 的兼容性:

  • stdio 流(stdinstdoutstderr)会作为 Socket 实例暴露,与 Node.js 行为一致。
  • Shell 重定向(><>>)可在 exec()execSync() 中正常工作。
  • fork() 接受 URL 作为模块路径。
  • timeoutkillSignal 选项在 exec()spawn() 中受到支持。
  • NODE_OPTIONS 环境变量会被 fork() 的子进程遵循。

node:zlib Jump to heading

Deno 2.7 为 node:zlib 添加了 Zstd 压缩支持:

import zlib from "node:zlib";
import { promisify } from "node:util";

const compress = promisify(zlib.zstdCompress);
const decompress = promisify(zlib.zstdDecompress);

const compressed = await compress(Buffer.from("你好,Deno!"));
const result = await decompress(compressed);
console.log(result.toString()); // "你好,Deno!"

同步版本 zlib.zstdCompressSync()zlib.zstdDecompressSync() 也可用。

node:sqlite Jump to heading

Deno 2.7 为 node:sqlite 添加了多个新 API:

  • DatabaseSync.setAuthorizer(callback) — 注册一个回调,该回调会在 每次 SQL 操作时被调用,从而能够对允许哪些表和操作进行细粒度访问控制:
import { constants, DatabaseSync } from "node:sqlite";

const db = new DatabaseSync(":memory:");
db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)");

// 允许读取,拒绝其他所有操作
db.setAuthorizer((_action, _table) => {
  return constants.SQLITE_OK;
});
  • DatabaseSync.enableDefensive(enabled) — 启用或禁用防御模式, 该模式可阻止某些潜在危险的数据库操作,例如在运行时修改 schema。

  • DatabaseSync.createTagStore() — 创建一个预处理语句缓存,将 SQL 字符串映射到已编译语句,以便高效重复执行。

Node 测试结果 Jump to heading

如果你想更详细地了解每个测试用例的兼容性,可以在此页面查看通过和失败的 Node.js 测试用例列表。

Last updated on

Did you find what you needed?

编辑此页面
Privacy policy