Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
370 views
in Technique[技术] by (71.8m points)

javascript - 从子目录找不到模块Windows 10(Cannot find module windows 10 from subdirectory)

I am trying to run a node.js script from a walkthrough I found online however I am gettings errors early on.(我正在尝试从网上找到的演练中运行node.js脚本,但是我很早就遇到了错误。)

(Link to walkthrough I am trying to go through) https://www.education-ecosystem.com/elliottminns/l5DN4-how-to-create-a-cryptocurrency-trading-bot-in-nodejs/q6knD-how-to-create-a-cryptocurrency-trading-bot-in-no-7/((链接至我正在尝试的演练) https://www.education-ecosystem.com/elliottminns/l5DN4-how-to-create-a-cryptocurrency-trading-bot-in-nodejs/q6knD-how-to -在没有7 /的情况下创建一个加密货币交易机器人) When I run the code with Node.js in windows 10 its give me an error where it can't find the other modules or other .js files in the subdirectory.(当我在Windows 10中使用Node.js运行代码时,它给我一个错误,提示它在子目录中找不到其他模块或其他.js文件。) I know this is something probably super simple but when I look around, I think I getting the wrong information.(我知道这可能非常简单,但是当我环顾四周时,我认为我得到了错误的信息。) I use Brackets to look at the project folders and .js files, and I use cmd with node or node.js to run the index.js file.(我使用方括号查看项目文件夹和.js文件,并将cmd与node或node.js一起使用以运行index.js文件。) 在此处输入图片说明 在此处输入图片说明   ask by Jaton Jameer Justice translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.(如果模块名称有.//../ ,它会寻找在给定的路径的目录/文件。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...