核心模块


【Core 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 core modules are defined within the Node.js source and are located in the lib/ folder.】

核心模块可以通过使用 node: 前缀来识别,在这种情况下,它会绕过 require 缓存。例如,require('node:http') 将始终返回内置的 HTTP 模块,即使 require.cache 中存在同名条目。

【Core 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 core 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 core modules that can be loaded without using the node: prefix is exposed as module.builtinModules.】