DEV Community

Cover image for How I Solved Heroku H10 / 503 Error - A Story
Efosa Collins EVBOWE
Efosa Collins EVBOWE

Posted on

How I Solved Heroku H10 / 503 Error - A Story

It was a beautiful afternoon and the time was 2:17 pm. The sun was radiating hot and the rays of the sun were freely flashing into the room where I was coding.
By 2:30 pm I had completed the code for my CRUD todo-list which was ready for deployment according to my level of understanding.

I logged in to Heroku which is a platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud. Some months ago, I deployed a Node.js app on the platform so I decided to follow the documentation created for deploying an existing application to Heroku.

After following the documentation cautiously, I got lost then I decided to Google search with the query:

How to solve Heroku H10 error

Before this, I already searched MDN Docs for 503 error which was reported to be Service Unavailable which meant my server wasn't ready to handle a request.

From the result I got from my Google search, I was led to Heroku docs on their errors which was just about the error with nothing to solve it --as-expected.

But with the search I did on 503 and H10, it was clear to me that the only thing causing the error was my code. I searched for How to solve the Heroku H10 error again but with faith, this time and I found a blog post on Dev which listed in detail all I needed to do.

Following this post, I did this:

  • Bug in Procfile

I made sure there was no bug in my Procfile since a little space could trigger Heroku errors.

web: node app.js not web : node app.js

  • Set Heroku's PORT

I reviewed my code making sure I had set the right Heroku port for Express servers which is process.env.PORT

app.listen(process.env.PORT || 3000, function () {
  console.log("The server has started successfully");
});
Enter fullscreen mode Exit fullscreen mode
  • Required Environment Variable

The app I created had a database and I didn't set my database URI on Heroku. All I had to do was get my Database's URI and enlist it as a Config Variable on Heroku.

Where to set Config Var on Heroku

  • Set Start Scripts

I didn't have my start script in my package.json which might have caused the app to crash so I added it to be on the safer side.

"scripts": {
    "start": "node app.js"
  }
Enter fullscreen mode Exit fullscreen mode

I had already set my node engine and I was good to go.

"engines": {
    "node": "16.14.2"
  }
Enter fullscreen mode Exit fullscreen mode

Finally, I did the rituals git add ., git commit -m "msg" and heroku push origin main which pushed my code to its Heroku repo.

After all the drama, I restarted my dyno with heroku restart and my site was working. I became the happiest man alive at that moment.

THE END

I hope you solve your Heroku H10 error successfully. Follow me on Twitter @ EfeCollins7. I would like to hear your comments. Thanks.

Latest comments (0)