The line(线)
const app = require("app");
will make Node attempt to load a module called app
from the node_modules
folder.(将使Node尝试从node_modules
文件夹中加载名为app
的模块。)
Obviously, this is not what you want – instead, you need to load a file which is located relative to the current file.(显然,这不是您想要的-相反,您需要加载相对于当前文件而言的文件。) To specify a relative load path, use this:(要指定相对加载路径,请使用以下命令:)
const app = require("./app");
Node will then look for a file or directory called app
.(然后,节点将查找名为app
的文件或目录。) If it's a directory, it will load index.js
from it.(如果是目录,它将从中加载index.js
。)
An excerpt from this article :(本文摘录:)
The require function will look for files in the following order:(require函数将按以下顺序查找文件:)
Built-in core Node.js modules (like fs
)(内置的核心Node.js模块(如fs
))
NPM Modules.(NPM模块。) It will look in the node_modules
folder(它将在node_modules
文件夹中查找)
Local Modules.(本地模块。) If the module name has a ./
, /
or ../
, it will look for the directory/file in the given path.(如果模块名称有./
, /
或../
,它会寻找在给定的路径的目录/文件。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…