内置模块
¥Built-in modules
Node.js 有些模块编译成二进制文件。这些模块在本文档的其他地方有更详细的描述。
¥Node.js has several modules compiled into the binary. These modules are described in greater detail elsewhere in this documentation.
内置模块在 Node.js 源中定义,位于 lib/
文件夹中。
¥The built-in modules are defined within the Node.js source and are located in the
lib/
folder.
可以使用 node:
前缀标识内置模块,在这种情况下它会绕过 require
缓存。例如,require('node:http')
将始终返回内置的 HTTP 模块,即使有该名称的 require.cache
条目。
¥Built-in modules can be identified using the node:
prefix, in which case
it bypasses the require
cache. For instance, require('node:http')
will
always return the built in HTTP module, even if there is require.cache
entry
by that name.
如果某些内置模块的标识符传递给 require()
,则始终优先加载它们。例如,require('http')
将始终返回内置的 HTTP 模块,即使存在该名称的文件。无需使用 node:
前缀即可加载的内置模块列表显示为 module.builtinModules
。
¥Some built-in modules are always preferentially loaded if their identifier is
passed to require()
. For instance, require('http')
will always
return the built-in HTTP module, even if there is a file by that name. The list
of built-in modules that can be loaded without using the node:
prefix is exposed
as module.builtinModules
.