- 断言测试
- 异步上下文跟踪
- 异步钩子
- 缓冲(Buffer)
- C++ 插件
- 使用 Node-API 的 C/C++ 插件
- C++ 嵌入 Node环境
- 子进程(Child processes)
- 集群(Cluster)
- 命令行选项
- 控制台(Console)
- 核心包(Corepack)
- 加密(Crypto)
- 调试器(Debugger)
- 已弃用的 API
- 诊断通道(Diagnostics Channel)
- 域名系统(DNS)
- 域(Domain)
- 错误(Errors)
- 事件(Events)
- 文件系统(File system)
- 全局变量(Globals)
- HTTP
- HTTP/2
- HTTPS
- 检查器(Inspector)
- 国际化
- 模块:CommonJS 模块
- 模块:ECMAScript 模块
- 模块:
node:moduleAPI - 模块:packages 模块
- 网络(Net)
- 系统(OS)
- 路径(Path)
- 性能挂钩(Performance hooks)
- 性能挂钩(Permissions)
- 进程(Process)
- Punycode 国际化域名编码
- 查询字符串(Query strings)
- 命令行库(Readline)
- REPL 交互式编程环境
- 诊断报告
- 单个可执行应用程序
- Stream 流
- 字符串解码器
- 单元测试
- 定时器(Timers)
- 传输层安全/SSL
- 跟踪事件
- TTY
- UDP/数据报
- URL
- 实用程序
- V8
- 虚拟机
- WebAssembly
- Web加密 API(Web Crypto API)
- 网络流 API(Web Streams API)
- 工作线程(Worker threads)
- zlib
Node.js v18.18.2 文档
- Node.js v18.18.2
-
►
目录
- 已弃用的 API
- 撤销弃用
- 已弃用的 API 列表
- DEP0001:
http.OutgoingMessage.prototype.flush - DEP0002:
require('_linklist') - DEP0003:
_writableState.buffer - DEP0004:
CryptoStream.prototype.readyState - DEP0005:
Buffer()构造函数 - DEP0006:
child_processoptions.customFds - DEP0007: Replace
clusterworker.suicidewithworker.exitedAfterDisconnect - DEP0008:
require('node:constants') - DEP0009:
crypto.pbkdf2without digest - DEP0010:
crypto.createCredentials - DEP0011:
crypto.Credentials - DEP0012:
Domain.dispose - DEP0013:
fsasynchronous function without callback - DEP0014:
fs.readlegacy String interface - DEP0015:
fs.readSynclegacy String interface - DEP0016:
GLOBAL/root - DEP0017:
Intl.v8BreakIterator - DEP0018: Unhandled promise rejections
- DEP0019:
require('.')resolved outside directory - DEP0020:
Server.connections - DEP0021:
Server.listenFD - DEP0022:
os.tmpDir() - DEP0023:
os.getNetworkInterfaces() - DEP0024:
REPLServer.prototype.convertToContext() - DEP0025:
require('node:sys') - DEP0026:
util.print() - DEP0027:
util.puts() - DEP0028:
util.debug() - DEP0029:
util.error() - DEP0030:
SlowBuffer - DEP0031:
ecdh.setPublicKey() - DEP0032:
node:domainmodule - DEP0033:
EventEmitter.listenerCount() - DEP0034:
fs.exists(path, callback) - DEP0035:
fs.lchmod(path, mode, callback) - DEP0036:
fs.lchmodSync(path, mode) - DEP0037:
fs.lchown(path, uid, gid, callback) - DEP0038:
fs.lchownSync(path, uid, gid) - DEP0039:
require.extensions - DEP0040:
node:punycodemodule - DEP0041:
NODE_REPL_HISTORY_FILEenvironment variable - DEP0042:
tls.CryptoStream - DEP0043:
tls.SecurePair - DEP0044:
util.isArray() - DEP0045:
util.isBoolean() - DEP0046:
util.isBuffer() - DEP0047:
util.isDate() - DEP0048:
util.isError() - DEP0049:
util.isFunction() - DEP0050:
util.isNull() - DEP0051:
util.isNullOrUndefined() - DEP0052:
util.isNumber() - DEP0053:
util.isObject() - DEP0054:
util.isPrimitive() - DEP0055:
util.isRegExp() - DEP0056:
util.isString() - DEP0057:
util.isSymbol() - DEP0058:
util.isUndefined() - DEP0059:
util.log() - DEP0060:
util._extend() - DEP0061:
fs.SyncWriteStream - DEP0062:
node --debug - DEP0063:
ServerResponse.prototype.writeHeader() - DEP0064:
tls.createSecurePair() - DEP0065:
repl.REPL_MODE_MAGICandNODE_REPL_MODE=magic - DEP0066:
OutgoingMessage.prototype._headers, OutgoingMessage.prototype._headerNames - DEP0067:
OutgoingMessage.prototype._renderHeaders - DEP0068:
node debug - DEP0069:
vm.runInDebugContext(string) - DEP0070:
async_hooks.currentId() - DEP0071:
async_hooks.triggerId() - DEP0072:
async_hooks.AsyncResource.triggerId() - DEP0073: Several internal properties of
net.Server - DEP0074:
REPLServer.bufferedCommand - DEP0075:
REPLServer.parseREPLKeyword() - DEP0076:
tls.parseCertString() - DEP0077:
Module._debug() - DEP0078:
REPLServer.turnOffEditorMode() - DEP0079: Custom inspection function on objects via
.inspect() - DEP0080:
path._makeLong() - DEP0081:
fs.truncate()using a file descriptor - DEP0082:
REPLServer.prototype.memory() - DEP0083: Disabling ECDH by setting
ecdhCurvetofalse - DEP0084: requiring bundled internal dependencies
- DEP0085: AsyncHooks sensitive API
- DEP0086: Remove
runInAsyncIdScope - DEP0089:
require('node:assert') - DEP0090: Invalid GCM authentication tag lengths
- DEP0091:
crypto.DEFAULT_ENCODING - DEP0092: Top-level
thisbound tomodule.exports - DEP0093:
crypto.fipsis deprecated and replaced - DEP0094: Using
assert.fail()with more than one argument - DEP0095:
timers.enroll() - DEP0096:
timers.unenroll() - DEP0097:
MakeCallbackwithdomainproperty - DEP0098: AsyncHooks embedder
AsyncResource.emitBeforeandAsyncResource.emitAfterAPIs - DEP0099: Async context-unaware
node::MakeCallbackC++ APIs - DEP0100:
process.assert() - DEP0101:
--with-lttng - DEP0102: Using
noAssertinBuffer#(read|write)operations - DEP0103:
process.binding('util').is[...]typechecks - DEP0104:
process.envstring coercion - DEP0105:
decipher.finaltol - DEP0106:
crypto.createCipherandcrypto.createDecipher - DEP0107:
tls.convertNPNProtocols() - DEP0108:
zlib.bytesRead - DEP0109:
http,https, andtlssupport for invalid URLs - DEP0110:
vm.Scriptcached data - DEP0111:
process.binding() - DEP0112:
dgramprivate APIs - DEP0113:
Cipher.setAuthTag(),Decipher.getAuthTag() - DEP0114:
crypto._toBuf() - DEP0115:
crypto.prng(),crypto.pseudoRandomBytes(),crypto.rng() - DEP0116: Legacy URL API
- DEP0117: Native crypto handles
- DEP0118:
dns.lookup()support for a falsy host name - DEP0119:
process.binding('uv').errname()private API - DEP0120: Windows Performance Counter support
- DEP0121:
net._setSimultaneousAccepts() - DEP0122:
tlsServer.prototype.setOptions() - DEP0123: setting the TLS ServerName to an IP address
- DEP0124: using
REPLServer.rli - DEP0125:
require('node:_stream_wrap') - DEP0126:
timers.active() - DEP0127:
timers._unrefActive() - DEP0128: modules with an invalid
mainentry and anindex.jsfile - DEP0129:
ChildProcess._channel - DEP0130:
Module.createRequireFromPath() - DEP0131: Legacy HTTP parser
- DEP0132:
worker.terminate()with callback - DEP0133:
httpconnection - DEP0134:
process._tickCallback - DEP0135:
WriteStream.open()andReadStream.open()are internal - DEP0136:
httpfinished - DEP0137: Closing fs.FileHandle on garbage collection
- DEP0138:
process.mainModule - DEP0139:
process.umask()with no arguments - DEP0140: Use
request.destroy()instead ofrequest.abort() - DEP0141:
repl.inputStreamandrepl.outputStream - DEP0142:
repl._builtinLibs - DEP0143:
Transform._transformState - DEP0144:
module.parent - DEP0145:
socket.bufferSize - DEP0146:
new crypto.Certificate() - DEP0147:
fs.rmdir(path, { recursive: true }) - DEP0148: Folder mappings in
"exports"(trailing"/") - DEP0149:
http.IncomingMessage#connection - DEP0150: Changing the value of
process.config - DEP0151: Main index lookup and extension searching
- DEP0152: Extension PerformanceEntry properties
- DEP0153:
dns.lookupanddnsPromises.lookupoptions type coercion - DEP0154: RSA-PSS generate key pair options
- DEP0155: Trailing slashes in pattern specifier resolutions
- DEP0156:
.abortedproperty and'abort','aborted'event inhttp - DEP0157: Thenable support in streams
- DEP0158:
buffer.slice(start, end) - DEP0159:
ERR_INVALID_CALLBACK - DEP0160:
process.on('multipleResolves', handler) - DEP0161:
process._getActiveRequests()andprocess._getActiveHandles() - DEP0162:
fs.write(),fs.writeFileSync()coercion to string - DEP0163:
channel.subscribe(onMessage),channel.unsubscribe(onMessage) - DEP0164:
process.exit(code),process.exitCodecoercion to integer - DEP0165:
--trace-atomics-wait - DEP0166: Double slashes in imports and exports targets
- DEP0167: Weak
DiffieHellmanGroupinstances (modp1,modp2,modp5) - DEP0168: Unhandled exception in Node-API callbacks
- DEP0169: Insecure url.parse()
- DEP0170: Invalid port when using
url.parse() - DEP0171: Setters for
http.IncomingMessageheaders and trailers
- DEP0001:
- 已弃用的 API
-
►
索引
- Assertion testing
- Asynchronous context tracking
- Async hooks
- Buffer
- C++ addons
- C/C++ addons with Node-API
- C++ embedder API
- Child processes
- Cluster
- Command-line options
- Console
- Corepack
- Crypto
- Debugger
- Deprecated APIs
- Diagnostics Channel
- DNS
- Domain
- Errors
- Events
- File system
- Globals
- HTTP
- HTTP/2
- HTTPS
- Inspector
- Internationalization
- Modules: CommonJS modules
- Modules: ECMAScript modules
- Modules:
node:moduleAPI - Modules: Packages
- Net
- 系统(OS)
- 路径(Path)
- Performance hooks
- Permissions
- 进程(Process)
- Punycode
- Query strings
- 命令行库(Readline)
- REPL 交互式编程环境
- Report
- Single executable applications
- Stream
- String decoder
- Test runner
- Timers
- TLS/SSL
- Trace events
- TTY
- UDP/datagram
- URL
- Utilities
- V8
- VM
- WASI
- Web Crypto API
- Web Streams API
- Worker threads
- Zlib
- ► 其他版本
- ► 选项
目录
- 已弃用的 API
- 撤销弃用
- 已弃用的 API 列表
- DEP0001:
http.OutgoingMessage.prototype.flush - DEP0002:
require('_linklist') - DEP0003:
_writableState.buffer - DEP0004:
CryptoStream.prototype.readyState - DEP0005:
Buffer()构造函数 - DEP0006:
child_processoptions.customFds - DEP0007:将
clusterworker.suicide替换为worker.exitedAfterDisconnect - DEP0008:
require('node:constants') - DEP0009:
crypto.pbkdf2没有摘要 - DEP0010:
crypto.createCredentials - DEP0011:
crypto.Credentials - DEP0012:
Domain.dispose - DEP0013:
fs异步函数,无回调 - DEP0014:
fs.read旧字符串接口 - DEP0015:
fs.readSync旧字符串接口 - DEP0016:
GLOBAL/root - DEP0017:
Intl.v8BreakIterator - DEP0018:未处理的 Promise 拒绝
- DEP0019:
require('.')已解析外部目录 - DEP0020:
Server.connections - DEP0021:
Server.listenFD - DEP0022:
os.tmpDir() - DEP0023:
os.getNetworkInterfaces() - DEP0024:
REPLServer.prototype.convertToContext() - DEP0025:
require('node:sys') - DEP0026:
util.print() - DEP0027:
util.puts() - DEP0028:
util.debug() - DEP0029:
util.error() - DEP0030:
SlowBuffer - DEP0031:
ecdh.setPublicKey() - DEP0032:
node:domain模块 - DEP0033:
EventEmitter.listenerCount() - DEP0034:
fs.exists(path, callback) - DEP0035:
fs.lchmod(path, mode, callback) - DEP0036:
fs.lchmodSync(path, mode) - DEP0037:
fs.lchown(path, uid, gid, callback) - DEP0038:
fs.lchownSync(path, uid, gid) - DEP0039:
require.extensions - DEP0040:
node:punycode模块 - DEP0041:
NODE_REPL_HISTORY_FILE环境变量 - DEP0042:
tls.CryptoStream - DEP0043:
tls.SecurePair - DEP0044:
util.isArray() - DEP0045:
util.isBoolean() - DEP0046:
util.isBuffer() - DEP0047:
util.isDate() - DEP0048:
util.isError() - DEP0049:
util.isFunction() - DEP0050:
util.isNull() - DEP0051:
util.isNullOrUndefined() - DEP0052:
util.isNumber() - DEP0053:
util.isObject() - DEP0054:
util.isPrimitive() - DEP0055:
util.isRegExp() - DEP0056:
util.isString() - DEP0057:
util.isSymbol() - DEP0058:
util.isUndefined() - DEP0059:
util.log() - DEP0060:
util._extend() - DEP0061:
fs.SyncWriteStream - DEP0062:
node --debug - DEP0063:
ServerResponse.prototype.writeHeader() - DEP0064:
tls.createSecurePair() - DEP0065:
repl.REPL_MODE_MAGIC和NODE_REPL_MODE=magic - DEP0066:
OutgoingMessage.prototype._headers, OutgoingMessage.prototype._headerNames - DEP0067:
OutgoingMessage.prototype._renderHeaders - DEP0068:
node debug - DEP0069:
vm.runInDebugContext(string) - DEP0070:
async_hooks.currentId() - DEP0071:
async_hooks.triggerId() - DEP0072:
async_hooks.AsyncResource.triggerId() - DEP0073:
net.Server的几个内部属性 - DEP0074:
REPLServer.bufferedCommand - DEP0075:
REPLServer.parseREPLKeyword() - DEP0076:
tls.parseCertString() - DEP0077:
Module._debug() - DEP0078:
REPLServer.turnOffEditorMode() - DEP0079:通过
.inspect()对对象进行自定义检查功能 - DEP0080:
path._makeLong() - DEP0081:使用文件描述符的
fs.truncate() - DEP0082:
REPLServer.prototype.memory() - DEP0083:通过将
ecdhCurve设置为false来禁用 ECDH - DEP0084:需要捆绑的内部依赖项
- DEP0085:AsyncHooks 敏感 API
- DEP0086:删除
runInAsyncIdScope - DEP0089:
require('node:assert') - DEP0090:GCM 身份验证标签长度无效
- DEP0091:
crypto.DEFAULT_ENCODING - DEP0092:顶级
this绑定到module.exports - DEP0093:
crypto.fips已弃用并被替换 - DEP0094:将
assert.fail()与多个参数一起使用 - DEP0095:
timers.enroll() - DEP0096:
timers.unenroll() - DEP0097:具有
domain属性的MakeCallback - DEP0098:AsyncHooks 嵌入
AsyncResource.emitBefore和AsyncResource.emitAfterAPI - DEP0099:异步上下文不感知的
node::MakeCallbackC++ API - DEP0100:
process.assert() - DEP0101:
--with-lttng - DEP0102:在
Buffer#(read|write)操作中使用noAssert - DEP0103:
process.binding('util').is[...]类型检查 - DEP0104:
process.env字符串强制转换 - DEP0105:
decipher.finaltol - DEP0106:
crypto.createCipher和crypto.createDecipher - DEP0107:
tls.convertNPNProtocols() - DEP0108:
zlib.bytesRead - DEP0109:
http、https和tls对无效 URL 的支持 - DEP0110:
vm.Script缓存数据 - DEP0111:
process.binding() - DEP0112:
dgram私有 API - DEP0113:
Cipher.setAuthTag(),Decipher.getAuthTag() - DEP0114:
crypto._toBuf() - DEP0115:
crypto.prng()、crypto.pseudoRandomBytes()、crypto.rng() - DEP0116:旧版 URL API
- DEP0117:本机加密句柄
- DEP0118:
dns.lookup()支持虚假主机名 - DEP0119:
process.binding('uv').errname()私有 API - DEP0120:Windows 性能计数器支持
- DEP0121:
net._setSimultaneousAccepts() - DEP0122:
tlsServer.prototype.setOptions() - DEP0123:将 TLS ServerName 设置为 IP 地址
- DEP0124:使用
REPLServer.rli - DEP0125:
require('node:_stream_wrap') - DEP0126:
timers.active() - DEP0127:
timers._unrefActive() - DEP0128:具有无效
main条目和index.js文件的模块 - DEP0129:
ChildProcess._channel - DEP0130:
Module.createRequireFromPath() - DEP0131:旧版 HTTP 解析器
- DEP0132:带有回调的
worker.terminate() - DEP0133:
httpconnection - DEP0134:
process._tickCallback - DEP0135:
WriteStream.open()和ReadStream.open()是内部的 - DEP0136:
httpfinished - DEP0137:在垃圾回收时关闭 fs.FileHandle
- DEP0138:
process.mainModule - DEP0139:不带参数的
process.umask() - DEP0140:使用
request.destroy()而不是request.abort() - DEP0141:
repl.inputStream和repl.outputStream - DEP0142:
repl._builtinLibs - DEP0143:
Transform._transformState - DEP0144:
module.parent - DEP0145:
socket.bufferSize - DEP0146:
new crypto.Certificate() - DEP0147:
fs.rmdir(path, { recursive: true }) - DEP0148:
"exports"中的文件夹映射(尾随"/") - DEP0149:
http.IncomingMessage#connection - DEP0150:更改
process.config的值 - DEP0151:主索引查找和扩展搜索
- DEP0152:扩展 PerformanceEntry 属性
- DEP0153:
dns.lookup和dnsPromises.lookup选项类型强制 - DEP0154:RSA-PSS 生成密钥对选项
- DEP0155:模式说明符分辨率中的尾部斜杠
- DEP0156:
http中的.aborted属性和'abort'、'aborted'事件(Events) - DEP0157:流中的 thenable 支持
- DEP0158:
buffer.slice(start, end) - DEP0159:
ERR_INVALID_CALLBACK - DEP0160:
process.on('multipleResolves', handler) - DEP0161:
process._getActiveRequests()和process._getActiveHandles() - DEP0162:
fs.write()、fs.writeFileSync()强制转换为字符串 - DEP0163:
channel.subscribe(onMessage),channel.unsubscribe(onMessage) - DEP0164:
process.exit(code)、process.exitCode强制转换为整数 - DEP0165:
--trace-atomics-wait - DEP0166:进出口目标双倍大幅下调
- DEP0167:弱
DiffieHellmanGroup实例(modp1、modp2、modp5) - DEP0168:Node-API 回调中未处理的异常
- DEP0169:不安全的 url.parse()
- DEP0170:使用
url.parse()时端口无效 - DEP0171:
http.IncomingMessage标题和预告片的设置器
- DEP0001:
已弃用的 API#
Node.js API 可能会因以下原因而被弃用:
- 使用 API 是不安全的。
- 可以使用改进的替代 API。
- 预计未来的主要版本中会对 API 进行重大更改。
Node.js 使用三种弃用:
- 仅文档
- 运行
- 生命尽头
仅文档弃用是仅在 Node.js API 文档中表达的弃用。这些在运行 Node.js 时不会产生副作用。某些仅文档弃用会在使用--pending-deprecation标志(或其替代方案
NODE_PENDING_DEPRECATION=1环境变量)启动时触发运行时警告,类似于下面的运行时弃用。支持该标志的仅文档弃用在弃用 API 列表中明确标记为此类
。
默认情况下,运行时弃用将生成一个进程警告,该警告将在第一次使用已弃用的 API 时打印到stderr 。当
使用--throw-deprecation命令行标志时,运行时弃用将导致抛出错误。
当功能已或即将从 Node.js 中删除时,就会使用生命周期结束弃用。
撤销弃用#
有时,API 的弃用可能会被逆转。在这种情况下,本文件将使用与决策相关的信息进行更新。但是,弃用标识符不会被修改。
已弃用的 API 列表#
DEP0001:http.OutgoingMessage.prototype.flush#
类型: 报废
OutgoingMessage.prototype.flush()已被删除。请改用
OutgoingMessage.prototype.flushHeaders()。
DEP0002:require('_linklist')#
类型: 报废
_linklist模块已弃用。请使用用户态替代方案。
DEP0003:_writableState.buffer#
类型: 报废
_writableState.buffer已被删除。请改用_writableState.getBuffer()
。
DEP0004:CryptoStream.prototype.readyState#
类型: 报废
CryptoStream.prototype.readyState属性已删除。
DEP0005:Buffer()构造函数#
类型:运行时(支持--pending-deprecation)
由于 API 可用性问题可能会导致意外的安全问题,因此Buffer()函数和new Buffer()构造函数已弃用。
作为替代方案,可以使用以下方法之一来构造Buffer
对象:
Buffer.alloc(size[, fill[, encoding]]):创建一个具有 初始化内存的Buffer。Buffer.allocUnsafe(size):使用 未初始化的内存创建一个Buffer。Buffer.allocUnsafeSlow(size):使用未初始化的内存创建一个Buffer。Buffer.from(array):使用array的副本创建一个BufferBuffer.from(arrayBuffer[, byteOffset[, length]])- 创建一个包含给定arrayBuffer的Buffer。Buffer.from(buffer):创建一个复制buffer的Buffer。Buffer.from(string[, encoding]):创建一个 复制string的Buffer。
如果没有--pending-deprecation,则仅当代码不在
node_modules中时才会出现运行时警告。这意味着在依赖项中使用Buffer()不会出现弃用警告
。对于--pending-deprecation ,无论在何处使用Buffer()都会产生运行时警告。
DEP0006:child_process options.customFds#
类型: 报废
在child_process模块的spawn()、fork()和exec()
方法中,options.customFds选项已弃用。
应改用options.stdio选项。
DEP0007:将cluster worker.suicide替换为worker.exitedAfterDisconnect#
类型: 报废
在 Node.js cluster的早期版本中,名称为
suicide 的布尔属性已添加到Worker对象中。此属性的目的是提供有关Worker实例退出的方式和原因的指示。在 Node.js 6.0.0 中,旧属性已被弃用,并替换为新的
worker.exitedAfterDisconnect属性。旧的属性名称没有准确描述实际的语义,并且不必要地带有情感色彩。
DEP0008:require('node:constants')#
类型:仅文档
node:constants模块已弃用。当需要访问与特定 Node.js 内置模块相关的常量时,开发人员应改为引用相关模块公开的constants属性。例如,
require('node:fs').constants和require('node:os').constants。
DEP0009:crypto.pbkdf2没有摘要#
类型: 报废
Node.js 6.0 中已弃用在不指定摘要的情况下使用crypto.pbkdf2() API,因为该方法默认使用不推荐的
'SHA1'摘要。此前,打印了弃用警告。从 Node.js 8.0.0 开始,调用crypto.pbkdf2()或crypto.pbkdf2Sync()并将
digest设置为undefined将抛出TypeError。
从 Node.js v11.0.0 开始,在将digest设置为
null 的情况下调用这些函数将打印弃用警告,以与digest
为undefined时的行为保持一致。
然而现在,传递undefined或null将抛出TypeError。
DEP0010:crypto.createCredentials#
类型: 报废
crypto.createCredentials() API已删除。请改用
tls.createSecureContext()。
DEP0011:crypto.Credentials#
类型: 报废
crypto.Credentials类已删除。请改用tls.SecureContext
。
DEP0012:Domain.dispose#
类型: 报废
Domain.dispose()已被删除。相反,通过在域上设置的错误事件处理程序显式地从失败的 I/O 操作中恢复。
DEP0013: fs异步函数,无回调#
类型: 报废
从 Node.js 10.0.0 开始,调用不带回调的异步函数会抛出TypeError 。请参阅https://github.com/nodejs/node/pull/12562。
DEP0014:fs.read旧字符串接口#
类型: 报废
fs.read()旧版String接口已弃用。请改用
文档中提到的Buffer API。
DEP0015:fs.readSync旧字符串接口#
类型: 报废
fs.readSync()旧版String接口已弃用。请改用
文档中提到的Buffer API。
DEP0016:GLOBAL / root#
类型: 报废
global属性的GLOBAL和root别名在 Node.js 6.0.0 中已弃用,并已被删除。
DEP0017:Intl.v8BreakIterator#
类型: 报废
Intl.v8BreakIterator是非标准扩展,已被删除。请参阅Intl.Segmenter。
DEP0018:未处理的 Promise 拒绝#
类型: 报废
未处理的 Promise 拒绝已被弃用。默认情况下,未处理的 Promise 拒绝会以非零退出代码终止 Node.js 进程。要更改 Node.js 处理未处理拒绝的方式,请使用
--unhandled-rejections命令行选项。
DEP0019:require('.')已解析外部目录#
类型: 报废
在某些情况下,require('.')可能会在包目录之外进行解析。此行为已被删除。
DEP0020:Server.connections#
类型: 报废
Server.connections属性在 Node.js v0.9.7 中已弃用并已被删除。请改用Server.getConnections()方法。
DEP0021:Server.listenFD#
类型: 报废
Server.listenFD()方法已弃用并删除。请改用
Server.listen({fd: <number>})。
DEP0022:os.tmpDir()#
类型: 报废
os.tmpDir() API在 Node.js 7.0.0 中已弃用,现已被删除。请改用os.tmpdir()。
DEP0023:os.getNetworkInterfaces()#
类型: 报废
os.getNetworkInterfaces()方法已弃用。请改用
os.networkInterfaces()方法。
DEP0024:REPLServer.prototype.convertToContext()#
类型: 报废
REPLServer.prototype.convertToContext() API已被删除。
DEP0025:require('node:sys')#
类型:运行时
node:sys模块已弃用。请改用util模块。
DEP0026:util.print()#
类型: 报废
util.print()已被删除。请改用console.log()。
DEP0027:util.puts()#
类型: 报废
util.puts()已被删除。请改用console.log()。
DEP0028:util.debug()#
类型: 报废
util.debug()已被删除。请改用console.error()。
DEP0029:util.error()#
类型: 报废
util.error()已被删除。请改用console.error()。
DEP0030:SlowBuffer#
类型:仅文档
SlowBuffer类已弃用。请改用
Buffer.allocUnsafeSlow(size)。
DEP0031:ecdh.setPublicKey()#
类型:仅文档
ecdh.setPublicKey()方法现已弃用,因为将其包含在 API 中没有用处。
DEP0032:node:domain模块#
类型:仅文档
domain模块已弃用,不应使用。
DEP0033:EventEmitter.listenerCount()#
类型:仅文档
events.listenerCount(emitter, eventName) API已弃用。请改用emitter.listenerCount(eventName)。
DEP0034:fs.exists(path, callback)#
类型:仅文档
fs.exists(path, callback) API已弃用。请改用
fs.stat()或fs.access()。
DEP0035:fs.lchmod(path, mode, callback)#
类型:仅文档
fs.lchmod(path, mode, callback) API已弃用。
DEP0036:fs.lchmodSync(path, mode)#
类型:仅文档
fs.lchmodSync(path, mode) API已弃用。
DEP0037:fs.lchown(path, uid, gid, callback)#
类型:弃用已撤销
fs.lchown(path, uid, gid, callback) API已弃用。由于在 libuv 中添加了必需的支持 API,因此弃用已被撤销。
DEP0038:fs.lchownSync(path, uid, gid)#
类型:弃用已撤销
fs.lchownSync(path, uid, gid) API已弃用。由于在 libuv 中添加了必需的支持 API,因此弃用已被撤销。
DEP0039:require.extensions#
类型:仅文档
require.extensions属性已弃用。
DEP0040:node:punycode模块#
类型:仅文档(支持--pending-deprecation)
punycode模块已弃用。请改用用户态替代方案。
DEP0041:NODE_REPL_HISTORY_FILE环境变量#
类型: 报废
NODE_REPL_HISTORY_FILE环境变量已删除。请改用
NODE_REPL_HISTORY。
DEP0042:tls.CryptoStream#
类型: 报废
tls.CryptoStream类已删除。请改用
tls.TLSSocket。
DEP0043:tls.SecurePair#
类型:仅文档
tls.SecurePair类已弃用。请改用
tls.TLSSocket。
DEP0044:util.isArray()#
类型:仅文档
util.isArray() API已弃用。请改用Array.isArray()
。
DEP0045:util.isBoolean()#
类型:仅文档
util.isBoolean() API已弃用。
DEP0046:util.isBuffer()#
类型:仅文档
util.isBuffer() API已弃用。请改用
Buffer.isBuffer()。
DEP0047:util.isDate()#
类型:仅文档
util.isDate() API已弃用。
DEP0048:util.isError()#
类型:仅文档
util.isError() API已弃用。
DEP0049:util.isFunction()#
类型:仅文档
util.isFunction() API已弃用。
DEP0050:util.isNull()#
类型:仅文档
util.isNull() API已弃用。
DEP0051:util.isNullOrUndefined()#
类型:仅文档
util.isNullOrUndefined() API已弃用。
DEP0052:util.isNumber()#
类型:仅文档
util.isNumber() API已弃用。
DEP0053:util.isObject()#
类型:仅文档
util.isObject() API已弃用。
DEP0054:util.isPrimitive()#
类型:仅文档
util.isPrimitive() API已弃用。
DEP0055:util.isRegExp()#
类型:仅文档
util.isRegExp() API已弃用。
DEP0056:util.isString()#
类型:仅文档
util.isString() API已弃用。
DEP0057:util.isSymbol()#
类型:仅文档
util.isSymbol() API已弃用。
DEP0058:util.isUndefined()#
类型:仅文档
util.isUndefined() API已弃用。
DEP0059:util.log()#
类型:仅文档
util.log() API已弃用。
DEP0060:util._extend()#
类型:仅文档
util._extend() API已弃用。
DEP0061:fs.SyncWriteStream#
类型: 报废
fs.SyncWriteStream类从未打算成为可公开访问的 API,因此已被删除。没有可用的替代 API。请使用用户态替代方案。
DEP0062:node --debug#
类型: 报废
--debug激活旧版 V8 调试器界面,该界面从 V8 5.8 起已被删除。它被 Inspector 取代,后者通过--inspect激活
。
DEP0063:ServerResponse.prototype.writeHeader()#
类型:仅文档
node:http模块ServerResponse.prototype.writeHeader() API 已弃用。请改用ServerResponse.prototype.writeHead()。
ServerResponse.prototype.writeHeader()方法从未被记录为官方支持的 API。
DEP0064:tls.createSecurePair()#
类型:运行时
Node.js 0.11.3 的文档中已弃用tls.createSecurePair() API 。用户应使用tls.Socket代替。
DEP0065:repl.REPL_MODE_MAGIC和NODE_REPL_MODE=magic#
类型: 报废
用于replMode选项的node:repl模块的REPL_MODE_MAGIC常量已被删除。自 Node.js 6.0.0(导入 V8 5.0)以来,其行为在功能上与
REPL_MODE_SLOPPY相同。请改用
REPL_MODE_SLOPPY。
NODE_REPL_MODE环境变量用于设置
交互式node会话的基础replMode。它的值magic也被删除。请改用sloppy。
DEP0066:OutgoingMessage.prototype._headers, OutgoingMessage.prototype._headerNames#
类型:运行时
node:http模块OutgoingMessage.prototype._headers和
OutgoingMessage.prototype._headerNames属性已弃用。使用公共方法之一(例如OutgoingMessage.prototype.getHeader()、
OutgoingMessage.prototype.getHeaders()、
OutgoingMessage.prototype.getHeaderNames()、
OutgoingMessage.prototype.getRawHeaderNames()、
OutgoingMessage.prototype.hasHeader()、
OutgoingMessage.prototype.removeHeader()、
OutgoingMessage.prototype.setHeader() ) 用于处理传出标头。
OutgoingMessage.prototype._headers和
OutgoingMessage.prototype._headerNames属性从未被记录为官方支持的属性。
DEP0067:OutgoingMessage.prototype._renderHeaders#
类型:仅文档
node:http模块OutgoingMessage.prototype._renderHeaders() API 已弃用。
OutgoingMessage.prototype._renderHeaders属性从未被记录为官方支持的 API。
DEP0068:node debug#
类型: 报废
node debug对应于旧版 CLI 调试器,已被替换为可通过node inspect获取的基于 V8 检查器的 CLI 调试器。
DEP0069:vm.runInDebugContext(string)#
类型: 报废
DebugContext 已在 V8 中删除,并且在 Node.js 10+ 中不可用。
DebugContext 是一个实验性 API。
DEP0070:async_hooks.currentId()#
类型: 报废
为了清楚起见, async_hooks.currentId()已重命名为async_hooks.executionAsyncId()。
此更改是在async_hooks还是实验性 API 时进行的。
DEP0071:async_hooks.triggerId()#
类型: 报废
为了清楚起见, async_hooks.triggerId()已重命名为async_hooks.triggerAsyncId()。
此更改是在async_hooks还是实验性 API 时进行的。
DEP0072:async_hooks.AsyncResource.triggerId()#
类型: 报废
为了清楚起见, async_hooks.AsyncResource.triggerId()已重命名为
async_hooks.AsyncResource.triggerAsyncId()。
此更改是在async_hooks还是实验性 API 时进行的。
DEP0073:net.Server的几个内部属性#
类型: 报废
不推荐使用不适当的名称访问net.Server实例的多个内部、未记录的属性。
由于原始 API 没有文档记录,并且通常对非内部代码没有用处,因此不提供替代 API。
DEP0074:REPLServer.bufferedCommand#
类型: 报废
REPLServer.bufferedCommand属性已被弃用,取而代之的是
REPLServer.clearBufferedCommand()。
DEP0075:REPLServer.parseREPLKeyword()#
类型: 报废
REPLServer.parseREPLKeyword()已从用户态可见性中删除。
DEP0076:tls.parseCertString()#
类型: 报废
tls.parseCertString()是一个简单的解析助手,被错误地公开。虽然它应该解析证书主题和颁发者字符串,但它从未正确处理多值相对可分辨名称。
本文档的早期版本建议使用querystring.parse()作为tls.parseCertString()的替代方案。但是,querystring.parse()也无法正确处理所有证书主题,因此不应使用。
DEP0077:Module._debug()#
类型:运行时
Module._debug()已弃用。
Module._debug()函数从未被记录为官方支持的 API。
DEP0078:REPLServer.turnOffEditorMode()#
类型: 报废
REPLServer.turnOffEditorMode()已从用户态可见性中移除。
DEP0079:通过.inspect()对对象进行自定义检查功能#
类型: 报废
不推荐使用对象上名为inspect的属性来指定util.inspect()的自定义检查函数。请改用util.inspect.custom
。为了向后兼容 6.4.0 版本之前的 Node.js,两者都可以指定。
DEP0080:path._makeLong()#
类型:仅文档
内部path._makeLong()不适合公共使用。然而,用户层模块发现它很有用。内部 API 已弃用,并替换为相同的公共path.toNamespacedPath()方法。
DEP0081:使用文件描述符的fs.truncate()#
类型:运行时
不推荐使用fs.truncate() fs.truncateSync()与文件描述符一起使用。请使用fs.ftruncate()或fs.ftruncateSync()来处理文件描述符。
DEP0082:REPLServer.prototype.memory()#
类型: 报废
REPLServer.prototype.memory()仅对于REPLServer本身的内部机制是必需的。不要使用此功能。
DEP0083:通过将ecdhCurve设置为false来禁用 ECDH#
类型:寿命终结。
tls.createSecureContext()和tls.TLSSocket的 ecdhCurve 选项可以设置为false以仅在服务器上完全禁用 ECDH。为了准备迁移到 OpenSSL 1.1.0 并与客户端保持一致,此模式已被弃用,现在不受支持。请改用ciphers参数。
DEP0084:需要捆绑的内部依赖项#
类型: 报废
从 Node.js 版本 4.4.0 和 5.2.0 开始,一些仅供内部使用的模块会通过require()错误地暴露给用户代码。这些模块是:
v8/tools/codemapv8/tools/consarrayv8/tools/csvparserv8/tools/logreaderv8/tools/profile_viewv8/tools/profilev8/tools/SourceMapv8/tools/splaytreev8/tools/tickprocessor-driverv8/tools/tickprocessornode-inspect/lib/_inspect(从 7.6.0 开始)node-inspect/lib/internal/inspect_client(从 7.6.0 开始)node-inspect/lib/internal/inspect_repl(从 7.6.0 开始)
v8/*模块没有任何导出,如果不按特定顺序导入,实际上会引发错误。因此,几乎没有通过require()导入它们的合法用例。
另一方面,node-inspect可以通过包管理器在本地安装,因为它以相同的名称发布在 npm 注册表上。如果完成,则无需修改源代码。
DEP0085:AsyncHooks 敏感 API#
类型: 报废
AsyncHooks 敏感 API 从未被记录,并且存在各种小问题。请改用AsyncResource API。请参阅
https://github.com/nodejs/node/issues/15572。
DEP0086:删除runInAsyncIdScope#
类型: 报废
runInAsyncIdScope不会发出'before'或'after'事件,因此可能会导致很多问题。请参阅https://github.com/nodejs/node/issues/14328。
DEP0089:require('node:assert')#
类型:弃用已撤销
不建议直接导入断言,因为公开的函数使用松散的相等检查。弃用已被撤销,因为
不鼓励使用node:assert模块,并且弃用导致开发人员感到困惑。
DEP0090:GCM 身份验证标签长度无效#
类型: 报废
Node.js 用于支持 OpenSSL 在调用decipher.setAuthTag()时接受的所有 GCM 身份验证标记长度。从 Node.js v11.0.0 开始,仅允许 128、120、112、104、96、64 和 32 位的身份验证标记长度。根据NIST SP 800-38D,其他长度的身份验证标签无效
。
DEP0091:crypto.DEFAULT_ENCODING#
类型:运行时
crypto.DEFAULT_ENCODING属性已弃用。
DEP0092:顶级this绑定到module.exports#
类型:仅文档
不推荐将属性分配给顶级this作为module.exports的替代方案。开发者应使用exports
或module.exports。
DEP0093:crypto.fips已弃用并被替换#
类型:仅文档
crypto.fips属性已弃用。请改用crypto.setFips()
和crypto.getFips()。
DEP0094:将assert.fail()与多个参数一起使用#
类型:运行时
不推荐使用带有多个参数的assert.fail() 。仅使用
带有一个参数的assert.fail()或使用不同的node:assert模块方法。
DEP0095:timers.enroll()#
类型:运行时
timers.enroll()已弃用。请改用公开记录的
setTimeout()或setInterval()。
DEP0096:timers.unenroll()#
类型:运行时
timers.unenroll()已弃用。请改用公开记录的
clearTimeout()或clearInterval()。
DEP0097:具有domain属性的MakeCallback#
类型:运行时
添加domain属性来携带上下文的 MakeCallback 用户应开始使用MakeCallback或
CallbackScope的 async_context 变体,或高级AsyncResource类。
DEP0098:AsyncHooks 嵌入AsyncResource.emitBefore和AsyncResource.emitAfter API#
类型: 报废
AsyncHooks 提供的嵌入式 API 公开了.emitBefore()和
.emitAfter()方法,这些方法很容易被错误使用,从而导致不可恢复的错误。
请改用asyncResource.runInAsyncScope() API,它提供了更安全、更方便的替代方案。请参阅
https://github.com/nodejs/node/pull/18513。
DEP0099:异步上下文不感知的node::MakeCallback C++ API#
类型:编译时
可用于本机插件的某些版本的node::MakeCallback API 已弃用。请使用接受async_context参数的 API 版本
。
DEP0100:process.assert()#
类型:运行时
process.assert()已弃用。请改用assert模块。
这从来都不是一个记录在案的功能。
DEP0101:--with-lttng#
类型: 报废
--with-lttng编译时选项已被删除。
DEP0102:在Buffer#(read|write)操作中使用noAssert#
类型: 报废
使用noAssert参数不再具有任何功能。无论noAssert的值如何,所有输入都会得到验证。跳过验证可能会导致难以发现的错误和崩溃。
DEP0103:process.binding('util').is[...]类型检查#
类型:仅文档(支持--pending-deprecation)
一般情况下应避免使用process.binding() 。特别是类型检查方法可以使用util.types替换。
此弃用已被process.binding() API ( DEP0111 )的弃用所取代
。
DEP0104:process.env字符串强制转换#
类型:仅文档(支持--pending-deprecation)
将非字符串属性分配给process.env时,分配的值会隐式转换为字符串。如果分配的值不是字符串、布尔值或数字,则不推荐使用此行为。将来,此类分配可能会导致抛出错误。请先将该属性转换为字符串,然后再将其分配给process.env。
DEP0105:decipher.finaltol#
类型: 报废
decipher.finaltol()从未被记录在案,并且是decipher.final()的别名
。此 API 已被删除,建议使用
decipher.final()代替。
DEP0106:crypto.createCipher和crypto.createDecipher#
类型:运行时
必须避免使用crypto.createCipher()和crypto.createDecipher() ,因为它们使用弱密钥派生函数(无盐 MD5)和静态初始化向量。建议使用
带有随机盐的crypto.pbkdf2()或crypto.scrypt()派生密钥,并使用
crypto.createCipheriv()和crypto.createDecipheriv()获取分别是
Cipher和Decipher对象。
DEP0107:tls.convertNPNProtocols()#
类型: 报废
这是一个未记录的辅助函数,不适合在 Node.js 核心之外使用,并因取消 NPN(下一协议协商)支持而被废弃。
DEP0108:zlib.bytesRead#
类型:运行时
已弃用zlib.bytesWritten的别名。选择这个原始名称是因为将值解释为引擎读取的字节数也是有意义的,但与 Node.js 中公开这些名称下的值的其他流不一致。
DEP0109:http、https和tls对无效 URL 的支持#
类型: 报废
一些以前支持的(但严格无效)URL 通过
http.request()、http.get()、https.request()、
https.get()和tls.checkServerIdentity() API,因为这些 API 已被旧版url.parse() API 接受。上述 API 现在使用 WHATWG URL 解析器,该解析器需要严格有效的 URL。不推荐使用传递无效 URL,并且将来将删除支持。
DEP0110:vm.Script缓存数据#
类型:仅文档
produceCachedData选项已弃用。请改用
script.createCachedData()。
DEP0111:process.binding()#
类型:仅文档(支持--pending-deprecation)
process.binding()仅供 Node.js 内部代码使用。
虽然process.binding()一般来说尚未达到生命周期结束状态,但在启用策略时不可用。
DEP0112:dgram私有 API#
类型:运行时
node:dgram模块之前包含几个永远不会在 Node.js 核心之外访问的 API:Socket.prototype._handle、
Socket.prototype._receiving、Socket.prototype._bindState、
Socket.prototype._queue、Socket.prototype._reuseAddr、
Socket.prototype._healthCheck()、Socket.prototype._stopReceiving()和
dgram._createSocketHandle()。
DEP0113:Cipher.setAuthTag(),Decipher.getAuthTag()#
类型: 报废
Cipher.setAuthTag()和Decipher.getAuthTag()不再可用。他们从未被记录下来,并且在被召唤时会抛出。
DEP0114:crypto._toBuf()#
类型: 报废
crypto._toBuf()函数不适合供 Node.js 核心之外的模块使用,因此已被删除。
DEP0115:crypto.prng()、crypto.pseudoRandomBytes()、crypto.rng()#
类型:仅文档(支持--pending-deprecation)
在 Node.js 的最新版本中, crypto.randomBytes()和crypto.pseudoRandomBytes()之间没有区别
。后者与未记录的别名crypto.prng()和
crypto.rng()一起已被弃用,取而代之的是crypto.randomBytes(),并且可能会在未来版本中删除。
DEP0116:旧版 URL API#
类型:弃用已撤销
旧版URL API已弃用。这包括url.format()、
url.parse()、url.resolve()和旧版urlObject。请改用WHATWG URL API。
DEP0117:本机加密句柄#
类型: 报废
以前版本的 Node.js 通过Cipher、
Decipher 、 DiffieHellman、{ { 的 _handle属性公开内部原生对象的句柄{0836}}}、ECDH、Hash、Hmac、Sign和Verify类。_handle属性已被删除,因为对本机对象的不当使用可能会导致应用程序崩溃。
DEP0118:dns.lookup()支持虚假主机名#
类型:运行时
由于向后兼容性,以前版本的 Node.js 支持具有虚假主机名(例如dns.lookup(false))的 dns.lookup() 。这种行为没有记录,并且被认为在现实世界的应用程序中未使用。在 Node.js 的未来版本中它将成为一个错误。
DEP0119:process.binding('uv').errname()私有 API#
类型:仅文档(支持--pending-deprecation)
process.binding('uv').errname()已弃用。请改用
util.getSystemErrorName()。
DEP0120:Windows 性能计数器支持#
类型: 报废
Windows 性能计数器支持已从 Node.js 中删除。未记录的COUNTER_NET_SERVER_CONNECTION()、
COUNTER_NET_SERVER_CONNECTION_CLOSE()、COUNTER_HTTP_SERVER_REQUEST()、
COUNTER_HTTP_SERVER_RESPONSE()、COUNTER_HTTP_CLIENT_REQUEST()和
COUNTER_HTTP_CLIENT_RESPONSE()函数已被弃用。
DEP0121:net._setSimultaneousAccepts()#
类型:运行时
未记录的net._setSimultaneousAccepts()函数最初用于
在 Windows 上使用node:child_process和node:cluster模块时进行调试和性能调整。该功能通常没有用,正在被删除。请参阅此处的讨论:
https ://github.com/nodejs/node/issues/18391
DEP0122:tls Server.prototype.setOptions()#
类型:运行时
请改用Server.prototype.setSecureContext()。
DEP0123:将 TLS ServerName 设置为 IP 地址#
类型:运行时
RFC 6066不允许将 TLS ServerName 设置为 IP 地址 。这将在未来版本中被忽略。
DEP0124:使用REPLServer.rli#
类型: 报废
该属性是对实例本身的引用。
DEP0125:require('node:_stream_wrap')#
类型:运行时
node:_stream_wrap模块已弃用。
DEP0126:timers.active()#
类型:运行时
之前未记录的timers.active()已弃用。请改用公开记录的timeout.refresh()。如果需要重新引用超时,则可以使用timeout.ref() ,自 Node.js 10 起不会影响性能。
DEP0127:timers._unrefActive()#
类型:运行时
以前未记录的“私有” timers._unrefActive()已弃用。请改用公开记录的timeout.refresh()。如果需要取消引用超时,则可以使用timeout.unref() ,自 Node.js 10 起不会影响性能。
DEP0128:具有无效main条目和index.js文件的模块#
类型:运行时
具有无效main条目(例如,./does-not-exist.js)且顶级目录中
还具有index.js文件的模块将解析index.js文件。这已被弃用,并且会在未来的 Node.js 版本中引发错误。
DEP0129:ChildProcess._channel#
类型:运行时
spawn()和类似函数返回的子进程对象的_channel属性不适合公共使用。请改用ChildProcess.channel
。
DEP0130:Module.createRequireFromPath()#
类型: 报废
DEP0131:旧版 HTTP 解析器#
类型: 报废
12.0.0 之前的 Node.js 版本中默认使用的旧版 HTTP 解析器已被弃用,并已在 v13.0.0 中删除。在 v13.0.0 之前,
可以使用--http-parser=legacy命令行标志恢复使用旧解析器。
DEP0132:带有回调的worker.terminate()#
类型:运行时
不推荐将回调传递给worker.terminate()。请改用返回的
Promise,或工作线程的'exit'事件的侦听器。
DEP0133:http connection#
类型:仅文档
优先选择response.socket而不是response.connection,
优先选择request.socket而不是request.connection。
DEP0134:process._tickCallback#
类型:仅文档(支持--pending-deprecation)
process._tickCallback属性从未被记录为官方支持的 API。
DEP0135:WriteStream.open()和ReadStream.open()是内部的#
类型:运行时
WriteStream.open()和ReadStream.open()是未记录的内部 API,在用户空间中使用没有意义。文件流应始终通过相应的工厂方法fs.createWriteStream()
和fs.createReadStream())或通过在选项中传递文件描述符来打开。
DEP0136:http finished#
类型:仅文档
response.finished指示是否已调用response.end() ,而不是是否已发出'finish'并刷新底层数据。
请相应地使用response.writableFinished或response.writableEnded
以避免歧义。
为了维持现有行为,response.finished应替换为
response.writableEnded。
DEP0137:在垃圾回收时关闭 fs.FileHandle#
类型:运行时
不推荐允许在垃圾回收时关闭fs.FileHandle对象。将来,这样做可能会导致抛出错误并终止进程。
请确保当不再需要fs.FileHandle时,使用 FileHandle.prototype.close() 显式关闭
所有fs.FileHandle 对象:
const fsPromises = require('node:fs').promises;
async function openAndClose() {
let filehandle;
try {
filehandle = await fsPromises.open('thefile.txt', 'r');
} finally {
if (filehandle !== undefined)
await filehandle.close();
}
}
DEP0138:process.mainModule#
类型:仅文档
process.mainModule是仅限 CommonJS 的功能,而process全局对象与非 CommonJS 环境共享。不支持在 ECMAScript 模块中使用它。
它已被弃用,取而代之的是require.main,因为它具有相同的目的,并且仅在 CommonJS 环境中可用。
DEP0139:不带参数的process.umask()#
类型:仅文档
不带参数调用process.umask()会导致进程范围的 umask 被写入两次。这引入了线程之间的竞争条件,并且是一个潜在的安全漏洞。没有安全的、跨平台的替代 API。
DEP0140:使用request.destroy()而不是request.abort()#
类型:仅文档
使用request.destroy()而不是request.abort()。
DEP0141:repl.inputStream和repl.outputStream#
类型:仅文档(支持--pending-deprecation)
node:repl模块导出输入和输出流两次。使用.input
代替.inputStream和.output代替.outputStream。
DEP0142:repl._builtinLibs#
类型:仅文档
node:repl模块导出包含内置模块数组的_builtinLibs属性。到目前为止它还不完整,最好依赖require('node:module').builtinModules。
DEP0143:Transform._transformState#
类型:运行时
Transform._transformState将在未来版本中删除,由于实现的简化而不再需要它。
DEP0144:module.parent#
类型:仅文档(支持--pending-deprecation)
CommonJS 模块可以使用module.parent访问第一个需要它的模块
。此功能已被弃用,因为它在存在 ECMAScript 模块的情况下无法一致工作,并且它提供的 CommonJS 模块图的表示不准确。
某些模块使用它来检查它们是否是当前进程的入口点。相反,建议比较require.main和module:
if (require.main === module) {
// Code section that will run only if current file is the entry point.
}
当查找需要当前模块的 CommonJS 模块时,
可以使用require.cache和module.children :
const moduleParents = Object.values(require.cache)
.filter((m) => m.children.includes(module));
DEP0145:socket.bufferSize#
类型:仅文档
socket.bufferSize只是writable.writableLength的别名。
DEP0146:new crypto.Certificate()#
类型:仅文档
crypto.Certificate()构造函数已弃用。请改用
crypto.Certificate()的静态方法。
DEP0147:fs.rmdir(path, { recursive: true })#
类型:运行时
在 Node.js 的未来版本中,对于 fs.rmdir、fs.rmdirSync和fs.promises.rmdir ,将忽略 recursive 选项
。
请改用fs.rm(path, { recursive: true, force: true })、
fs.rmSync(path, { recursive: true, force: true })或
fs.promises.rm(path, { recursive: true, force: true })。
DEP0148:"exports"中的文件夹映射(尾随"/")#
类型:运行时
不推荐使用尾随"/"在子路径导出或子路径导入字段中定义子路径文件夹映射
。请改用
子路径模式。
DEP0149:http.IncomingMessage#connection#
类型:仅文档。
优先选择message.socket而不是message.connection。
DEP0150:更改process.config的值#
类型: 报废
process.config属性提供对 Node.js 编译时设置的访问。然而,该属性是可变的,因此容易被篡改。Node.js 的未来版本将删除更改值的功能。
DEP0151:主索引查找和扩展搜索#
类型:运行时
以前,index.js和扩展搜索查找将应用于
import 'pkg'主入口点解析,即使在解析 ES 模块时也是如此。
通过此弃用,所有 ES 模块主入口点解析都需要具有确切文件扩展名的显式"exports"或"main"条目。
DEP0152:扩展 PerformanceEntry 属性#
类型:运行时
'gc'、'http2'和'http' <PerformanceEntry>对象类型分配有附加属性,可提供附加信息。这些属性现在可在 PerformanceEntry 对象的标准detail属性中使用。现有的访问器已被弃用,不应再使用。
DEP0153:dns.lookup和dnsPromises.lookup选项类型强制#
类型: 报废
对family选项使用非空非整数值,对hints选项使用非空非数字值,对all选项,或dns.lookup()中的verbatim选项
的非空非布尔值,并且dnsPromises.lookup()会引发
ERR_INVALID_ARG_TYPE错误。
DEP0154:RSA-PSS 生成密钥对选项#
类型:仅文档(支持--pending-deprecation)
'hash'和'mgf1Hash'选项替换为'hashAlgorithm'
和'mgf1HashAlgorithm'。
DEP0155:模式说明符分辨率中的尾部斜杠#
类型:运行时
对于包"exports"和"imports"模式解析,不推荐重新映射以 "/" 结尾的说明符,例如import 'pkg/x/' 。
DEP0156:http 中的 .aborted属性和'abort'、'aborted'事件#
类型:仅文档
请改用<Stream> API,因为http.ClientRequest、
http.ServerResponse和http.IncomingMessage都是基于流的。检查stream.destroyed而不是.aborted属性,并侦听
'close'而不是'abort'、'aborted'事件。
.aborted属性和'abort'事件仅用于检测
.abort()调用。要提前关闭请求,请使用 Stream
.destroy([error]),然后检查.destroyed属性,并且'close'事件应该具有相同的效果。接收端还应检查
http.IncomingMessage 上的 readable.readableEnded 值,以了解它是中止还是正常销毁。
DEP0157:流中的 thenable 支持#
类型: 报废
Node.js 流的一个未记录的功能是在实现方法中支持 thenables。现在已弃用,请改用回调,并避免对流实现方法使用异步函数。
此功能导致用户遇到意想不到的问题,即用户以回调方式实现函数,但使用例如异步方法,这会导致错误,因为混合 Promise 和回调语义是无效的。
const w = new Writable({
async final(callback) {
await someOp();
callback();
},
});
DEP0158:buffer.slice(start, end)#
类型:仅文档
此方法已被弃用,因为它与Uint8Array.prototype.slice()不兼容
,后者是Buffer的超类。
使用buffer.subarray来代替,它可以做同样的事情。
DEP0159:ERR_INVALID_CALLBACK#
类型: 报废
由于增加了用于值类型验证的错误的更多混乱,因此删除了此错误代码。
DEP0160:process.on('multipleResolves', handler)#
类型:运行时。
该事件已被弃用,因为它不能与 V8 Promise 组合器一起使用,这降低了它的实用性。
DEP0161:process._getActiveRequests()和process._getActiveHandles()#
类型:仅文档
process._getActiveHandles()和process._getActiveRequests()函数
不适合公共使用,可以在未来版本中删除。
使用process.getActiveResourcesInfo()获取事件资源类型的列表,而不是实际的引用。
DEP0162:fs.write()、fs.writeFileSync()强制转换为字符串#
类型: 报废
隐式强制转换具有自己的toString属性的对象,作为fs.write()、fs.writeFile()、fs.appendFile()、
fs.writeFileSync()和fs.appendFileSync()中的第二个参数传递已弃用。将它们转换为原始字符串。
DEP0163:channel.subscribe(onMessage),channel.unsubscribe(onMessage)#
类型:仅文档
这些方法已被弃用,因为它们的使用方式不能使通道引用保持足够长的事件时间来接收事件。
使用diagnostics_channel.subscribe(name, onMessage)或
diagnostics_channel.unsubscribe(name, onMessage)来代替,它们可以做同样的事情。
DEP0164:process.exit(code)、process.exitCode强制转换为整数#
类型:仅文档
不推荐使用undefined、null、整数和整数字符串(例如'1')以外的值作为code参数的值在
process.exit()中并作为分配给process.exitCode的值。
DEP0165:--trace-atomics-wait#
类型:仅文档
--trace-atomics-wait标志已弃用。
DEP0166:进出口目标双倍大幅下调#
类型:运行时
不推荐使用映射到包含双斜杠(“/”或“\”)的路径的包导入和导出目标,并且在未来版本中将失败并出现解析验证错误。同样的弃用也适用于以斜杠开头或结尾的模式匹配。
DEP0167:弱DiffieHellmanGroup实例(modp1、modp2、modp5)#
类型:仅文档
众所周知的 MODP 组modp1、modp2和modp5已被弃用,因为它们无法抵御实际攻击。有关详细信息,请参阅RFC 8247 第 2.4 节。
这些组可能会在 Node.js 的未来版本中被删除。依赖这些组的应用程序应该使用更强的 MODP 组来进行评估。
DEP0168:Node-API 回调中未处理的异常#
类型:运行时
Node-API 回调中对未捕获异常的隐式抑制现已弃用。
如果 Node-API 回调中未处理异常,则设置标志--force-node-api-uncaught-exceptions-policy以强制 Node.js 发出'uncaughtException'事件。
DEP0169:不安全的 url.parse()#
类型:仅文档(支持--pending-deprecation)
url.parse()行为未标准化,容易出现具有安全隐患的错误。请改用WHATWG URL API。不会针对url.parse()漏洞发布 CVE。
DEP0170:使用url.parse()时端口无效#
类型:仅文档
url.parse()接受端口不是数字的网址。此行为可能会导致主机名欺骗和意外输入。这些 URL 将在 Node.js 的未来版本中引发错误,正如WHATWG URL API已经这样做的那样。
DEP0171:http.IncomingMessage标题和预告片的设置器#
类型:仅文档
在 Node.js 的未来版本中,message.headers、
message.headersDistinct、message.trailers和
message.trailersDistinct将是只读的。