Home > Back-end >  Having errors deploying Node server to heroku
Having errors deploying Node server to heroku

Time:11-27

I am deploying my Node Express server to heroku, and I have some error after I do git push heroku master. I am complete beginner to deploying apps to heroku. How do I fix this error?

What I have tried:

  • I have set process.env.PORT.
  • Adding a Procfile with web:node index.js in it
  • heroku 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

Also, I have fixed the nodemon in my package.json:

"scripts": {
   "start": "node index.js"
}

But I still have the error.

CodePudding user response:

It actually looks like its because nodemon is not found.

Nodemon should not be used in production or deployment, since you dont need/want to auto refresh your server in your production env.

To prevent this, simply add another field in your scripts section of your package.json file, and remove nodemon from "start". It should look similar to this:

"scripts": {
    "start": "index.js",
    "dev": "nodemon index.js"
  },

Now, when developing in your own machine, instead of calling npm start (or yarn start), call npm run dev (yarn run dev).

That way, heroku will never try to use nodemon during production and deployment, but you will be able to auto restart your server during development

Heroku will call npm start, and so if a nodemon command is here, it will fail.

CodePudding user response:

I found the solution. For those who may have the same problem with me, I simply add all my env variables in Heroku (Setting > Config Vars).

  • Related