[英]How do I run this node express app on Heroku?
I already have one app running on Heroku just fine which I created a few weeks ago for the first time.我已经有一个在 Heroku 上运行的应用程序很好,这是我几周前第一次创建的。
Here is the git repo for the functioning app - https://github.com/Sean-99-04/basic这是功能应用程序的 git 存储库 - https://github.com/Sean-99-04/basic
However when I try to run my newest app, it does not work.但是,当我尝试运行我最新的应用程序时,它不起作用。 It builds fine, but gives an application error when ran.
它构建良好,但在运行时会出现应用程序错误。
Here is the git repo for that - https://github.com/Sean-99-04/History-Blog这是 git 回购 - https://github.com/Sean-99-04/History-Blog
Also I am runnnig this through GitHub, not through Heroku CLI.此外,我通过 GitHub 运行此,而不是通过 Heroku CLI。
I have been searching online for the last 3 hours for answers and here are some things mentioned which I made sure to unclude:在过去的 3 个小时里,我一直在网上搜索答案,这里提到了一些我确保排除的事情:
I greatly appreciate any help and thank you in advance.我非常感谢任何帮助,并提前感谢您。
This is the error in logs:这是日志中的错误:
2021-01-11T16:50:16.910561+00:00 app[web.1]: npm ERR. 2021-01-11T16:50:16.910561+00:00 应用程序 [web.1]:npm 错误。 Failed at the history-blog@1.0.0 start script.
在 history-blog@1.0.0 启动脚本中失败。
2021-01-11T16:50:16.910689+00:00 app[web.1]: npm ERR. 2021-01-11T16:50:16.910689+00:00 应用程序 [web.1]:npm 错误。 This is probably not a problem with npm.
这可能不是 npm 的问题。 There is likely additional logging output above.
上面可能还有额外的日志记录 output。
2021-01-11T16:50:16.915638+00:00 app[web.1]: 2021-01-11T16:50:16.915638+00:00 应用程序[web.1]:
2021-01-11T16:50:16.915831+00:00 app[web.1]: npm ERR: A complete log of this run can be found in: 2021-01-11T16:50:16.915831+00:00 app[web.1]: npm ERR:此运行的完整日志可在以下位置找到:
2021-01-11T16:50:16.915958+00:00 app[web.1]: npm ERR. 2021-01-11T16:50:16.915958+00:00 应用程序 [web.1]:npm 错误。 /app/.npm/_logs/2021-01-11T16_50_16_911Z-debug.log
/app/.npm/_logs/2021-01-11T16_50_16_911Z-debug.log
2021-01-11T16:50:16.988688+00:00 heroku[web.1]: Process exited with status 1 2021-01-11T16:50:16.988688+00:00 heroku[web.1]:进程以状态 1 退出
2021-01-11T16:50:17.025320+00:00 heroku[web.1]: State changed from starting to crashed 2021-01-11T16:50:17.025320+00:00 heroku[web.1]: State 从开始变为崩溃
2021-01-11T16:50:17.966848+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=history-blog.herokuapp.com request_id=f274158b-5399-49ab-97d9-5a83bb387a13 fwd="95.147.237.100" dyno= connect= service= status=503 bytes= protocol=https 2021-01-11T16:50:17.966848+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=history-blog.herokuapp.com request_id=f274158b -5399-49ab-97d9-5a83bb387a13 fwd="95.147.237.100" dyno= connect= service= status=503 bytes= protocol=https
As mentioned in the comments, the failure was caused by trying to loading dotenv.如评论中所述,失败是由于尝试加载 dotenv 引起的。 The reason that happened despite Heroku's default NODE_ENV being
production
is that you're assigning in the check, which returns the string development
, which is truthy — so it gets loaded.尽管 Heroku 的默认 NODE_ENV 是
production
环境,但发生这种情况的原因是您在检查中分配,它返回字符串development
,这是真的——所以它被加载了。
What you have: if ((process.env.NODE_ENV = "development")) {
你有什么:
if ((process.env.NODE_ENV = "development")) {
What you want: if (process.env.NODE_ENV === "development") {
你想要什么:
if (process.env.NODE_ENV === "development") {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.