gpt4 book ai didi

node.js - Nodemon 一直在寻找 index.js

转载 作者:行者123 更新时间:2023-12-01 11:16:46 26 4
gpt4 key购买 nike

我的 Node 监视器 一直在寻找index.js ,但我想使用 app.js大多数人现在使用app.js .

enter image description here

如何更新我的 nodemon 以查找 app.js ?

我尝试卸载,重新安装没有帮助。

⚡️  vidjot  nodemon
[nodemon] 1.17.3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node index.js`
module.js:540
throw err;
^

Error: Cannot find module '/Users/bheng/Sites/vidjot/index.js'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
[nodemon] app crashed - waiting for file changes before starting...

包.json
{
"name": "vidjot",
"version": "1.0.0",
"description": "app to create video idea",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.3"
}
}

最佳答案

Nodemon 命令在您的 package.json 文件中搜索主要属性并尝试执行它的文件。例子:

{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "henriquelborges",
"license": "ISC"
}

您可以将“main”:index.js”更改为“main”:“app.js”。或者您可以运行“nodemon filename”来指定入口文件。我通常做的是在我的package.json中添加脚本。示例:
"scripts": {
"start": "node app.js",
"test": "nodemon app.js"
},

在此之后,我只需在我的项目根文件夹中使用“npm start”或“npm test”之类的命令。像 Heroku 这样的云应用程序平台需要在你的 package.json 中添加“npm start”才能执行你的应用程序。如果您需要从命令行加载其他 npm 模块,将 npm 命令添加到项目中也很有用。

示例 - 您可以加载环境变量以在 localhost 上测试您的应用程序:

"test": "nodemon -r dotenv/config app.js dotenv_config_path=./config.env"

关于node.js - Nodemon 一直在寻找 index.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49820328/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com