弃用的 API
【Deprecated APIs】
Node.js API 可能由于以下任何原因而被弃用:
【Node.js APIs might be deprecated for any of the following reasons:】
- 使用该 API 不安全。
- 有一个改进的替代 API 可用。
- 预计在未来的主要版本中,API将会有重大变更。
Node.js 使用了三种弃用:
【Node.js uses three kinds of Deprecations:】
- 仅限文档
- 运行时
- 生命终结
仅文档弃用是指仅在 Node.js API 文档中表达的弃用。在运行 Node.js 时,这些不会产生任何副作用。某些仅文档弃用在使用 --pending-deprecation 标志(或其替代的 NODE_PENDING_DEPRECATION=1 环境变量)启动时会触发运行时警告,类似于下面的运行时弃用。支持该标志的仅文档弃用将在已弃用 API 列表中明确标注。
【A Documentation-only deprecation is one that is expressed only within the
Node.js API docs. These generate no side-effects while running Node.js.
Some Documentation-only deprecations trigger a runtime warning when launched
with --pending-deprecation flag (or its alternative,
NODE_PENDING_DEPRECATION=1 environment variable), similarly to Runtime
deprecations below. Documentation-only deprecations that support that flag
are explicitly labeled as such in the
list of Deprecated APIs.】
运行时弃用默认会生成一个进程警告,该警告会在第一次使用已弃用的 API 时打印到 stderr。当使用 --throw-deprecation 命令行标志时,运行时弃用会导致抛出错误。
【A Runtime deprecation will, by default, generate a process warning that will
be printed to stderr the first time the deprecated API is used. When the
--throw-deprecation command-line flag is used, a Runtime deprecation will
cause an error to be thrown.】
当 Node.js 的某项功能正在或即将被移除时,会使用终止支持弃用。
【An End-of-Life deprecation is used when functionality is or will soon be removed from Node.js.】