简体   繁体   中英

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.

Here is the git repo for the functioning app - 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

Also I am runnnig this through GitHub, not through 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:

  • Procfile with code "web:node./server.js"
  • package.json with code "script": {"start": "node server.js"}
  • In server.js I have process.env.PORT and all other necessary process.env's

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. Failed at the history-blog@1.0.0 start script.

2021-01-11T16:50:16.910689+00:00 app[web.1]: npm ERR. This is probably not a problem with npm. There is likely additional logging output above.

2021-01-11T16:50:16.915638+00:00 app[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.915958+00:00 app[web.1]: npm ERR. /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:17.025320+00:00 heroku[web.1]: State changed from starting to crashed

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. 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.

What you have: if ((process.env.NODE_ENV = "development")) {

What you want: if (process.env.NODE_ENV === "development") {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM