[英]Having errors deploying Node server to heroku
我正在将我的 Node Express 服务器部署到 heroku,并且在执行git push heroku master
之后出现了一些错误。 对于将应用程序部署到 heroku,我完全是初学者。 如何修复此错误?
我试过的:
process.env.PORT
。web:node index.js
的 Procfileheroku restart
2021-11-27T02:39:05.410712+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=logo-eshop.herokuapp.com request_id=fb4f6e95-de99-4135-9273-789af704557d fwd="79.66.155.39" dyno= connect= service= status=503 bytes= protocol=https
2021-11-27T02:39:05.650439+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=logo-eshop.herokuapp.com request_id=6572c3a7-f7c4-4ef6-ae09-cd4fcf0c6f5f fwd="79.66.155.39" dyno= connect= service= status=503 bytes= protocol=https
另外,我已经修复了我的nodemon
中的 nodemon:
"scripts": {
"start": "node index.js"
}
但我仍然有错误。
它实际上看起来像它,因为找不到 nodemon。
Nodemon 不应在生产或部署中使用,因为您不需要/不想在生产环境中自动刷新服务器。
为了防止这种情况,只需在 package.json 文件的脚本部分中添加另一个字段,然后从“开始”中删除 nodemon。 它应该类似于:
"scripts": {
"start": "index.js",
"dev": "nodemon index.js"
},
现在,在自己的机器上开发时,不要调用 npm start(或 yarn start),而是调用 npm run dev(yarn run dev)。
这样,heroku 将永远不会在生产和部署期间尝试使用 nodemon,但您将能够在开发期间自动重启服务器
Heroku 会调用 npm 启动,所以如果一个 nodemon 命令在这里,它会失败。
我找到了解决方案。 对于那些可能与我有同样问题的人,我只需将我所有的环境变量添加到env
(设置 > 配置变量)中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.