内置模块
【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.cache 条目,require('node:http') 也总是会返回内置的 HTTP 模块。
【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 模块,即使存在同名的文件。
【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.】
所有内置模块的列表可以从 module.builtinModules 获取。模块列表中均未带 node: 前缀,除了那些必须使用该前缀的模块(如下一节所述)。
【The list of all the built-in modules can be retrieved from module.builtinModules.
The modules being all listed without the node: prefix, except those that mandate such
prefix (as explained in the next section).】