We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
每日一题会在下午四点在交流群集中讨论,五点小程序中更新答案 欢迎大家在下方发表自己的优质见解 二维码加载失败可点击 小程序二维码
每日一题会在下午四点在交流群集中讨论,五点小程序中更新答案 欢迎大家在下方发表自己的优质见解
当 Node 遇到 require(X) 时,按照下面的顺序处理。
require(X)
require('http')
./
../
+----------------------+ | .x | | .x.js | | .x.json | | .x.node | +-------------------- +
+----------------------------+ | .X/package.json(main 字段) | | .X/index.js | | .X/index.json | | .X/index.node | +--------------------------- +
a.根据 X 所在的父模块,确定 X 可能的安装目录。 b.依次在每个目录中, 将 X 当成文件名或目录名加载
The text was updated successfully, but these errors were encountered:
No branches or pull requests
扫描下方二维码,收藏关注,及时获取答案以及详细解析,同时可解锁800+道前端面试题。
Require 内部逻辑(摘自官方文档)
当 Node 遇到
require(X)
时,按照下面的顺序处理。1)如果 X 是内置模块(比如
require('http')
)2)如果 X 以
./
或者../
开头3)如果 X 不带路径
a.根据 X 所在的父模块,确定 X 可能的安装目录。
b.依次在每个目录中, 将 X 当成文件名或目录名加载
4)抛出 "not found"
The text was updated successfully, but these errors were encountered: