How I Solved Heroku H10 / 503 Error - A Story
Tags: heroku, node, webdev, git
Published: 2022-10-19 10:35:01

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](http://todo-list-234.herokuapp.com/) which was ready for deployment according to my level of understanding.


I logged in to [Heroku](https://www.heroku.com/) 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](https://devcenter.heroku.com/articles/preparing-a-codebase-for-heroku-deployment).

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](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503) 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](https://devcenter.heroku.com/articles/error-codes#:~:text=start%20with%20L.-,H10%20%2D%20App%20crashed,dyno%20will%20present%20this%20error.) 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](https://dev.to/lawrence_eagles/causes-of-heroku-h10-app-crashed-error-and-how-to-solve-them-3jnl).

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");
});
```

- **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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n1mvpnl4reteiezw49bl.png)


- **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"
  }
```

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

```
"engines": {
    "node": "16.14.2"
  }
```

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](https://twitter.com/EfeCollins7). I would like to hear your comments. Thanks.