3 tricks for solving the `Heroku Application Error`

Oaes Kuruni
5 min readApr 18, 2020

--

After deploying your MongoDB site on Heroku you maybe not expecting this error.

photo by Google

Honestly speaking I’ve also faced this error while the first time I’ve hosted my application on Heroku. But don’t worry if you follow the steps then you will able to fix it and it will save time.

Ok, let’s jump into the process…..its dammm easy!!

At first, we have to check 3/4 things if it going great then we go for the next level.

First: (1) check your port which might be inside your index.js file/serve.js file. It should look like the following photo….

inside of index.js file

After that,

(2) Check your Heroku application’s setting you may forget to put `config vars` its looks like the following photos…

Heroku project setting page

Click the `Reveal config vars`

Heroku project setting page

And put your DB_PATH or you can put here separately DB_User and DB_Password

(3) After that, check your package.json file, inside dependencies you have to `nodemon`, if not please install `nodemon` by simply run this command in your terminal….

npm install nodemon --save

Now you can see the `nodemon` in your dependencies.

package.json file

After installing `nodemon` then run this command in your terminal, which is in below….

git add . // first
git comment -m 'added nodemon' // second
git push heroku master // last

If your problem is solved then take a coffee, if not follow the next steps.

Second: (1) Here, I recommend you to run the `heroku logs — tail` command in your terminal. You might be seen this type of logs……

after running Heroku logs — tail command

or,

after running Heroku logs — tail command

or,

after running Heroku logs — tail command

or,

after running Heroku logs — tail command

Or maybe different but try to find it, don’t give up. Mostly we got this `Application error` for not adding the `start` script inside package.json file. It looks like…

package.json file

(2) After adding the start within scripts, please follow this command..

git add . //first
git commit -m 'added script start'//second
git push heroku master//final

Then run the command `Heroku open`, I hope now you have seen your welcome title in the browser, if it again showing error then go with me into next steps.

(3) Little changes in `start` inside scripts….follow the pictures below…

package.json file

And again, after editing the start within scripts, please run this command..

git add . //firstgit commit -m 'editing package.json file' // second
git push heroku master //third
heroku open //final

Hopefully, now you may be got positive result!!!

If your problem is not resolved yet, don’t give up finish this article thoroughly.

Third: (1) Go to your MongoDB Atlas account and click the `connect` button which is marked by a blue-colored arrow, see the photo….

MongoDB Atlas clusters page

Then you will get this tab, see the next photos…..

MongoDB Atlas clusters page

And click the `connect your application` tab and follow the next steps…..see the next photos

MongoDB Atlas clusters page

Generally, by default it set the node.js version 3.0 or later and now we are going to change it a little lower version. See the next photos…

MongoDB Atlas clusters page

And after set the version, now we are going to copy the `connection string only` which is below this current page. See next photo….

MongoDB Atlas clusters page

By clicking the `copy` tab you can copy this connection string which you have to paste on your .env file for updating your existing DB_PATH and also paste it Heroku `config vars` which we have done before with node.js version 3.0.

(2) After setting the version now we add the `IP address` on MongoDB atlas. Don’t worry just follow the steps with photos…..

MongoDB Atlas Network Access page

In this photo, at first, just click the left sidebar’s `Network Access` tab then click the right side `Add IP address` button which is marked with the blue circle. Then follow the next steps, see the guide photos…

MongoDB Atlas Network Access page

Click the `allow access from anywhere` button and then `confirm`

It takes sometimes maybe 1/3 minutes for working.

After that please run this command again in your terminal…

heroku open

I hope now it works for you!!

Crazy tips: Again start your project on another folder/directory on your computer but don’t build its previous root, I mean if your project located on your c:drive project folder then create new folder on c:drive such as `heroku­_app` and follow the previous guide.

Believe me it don’t betray with you!!!

Happy coding:)

--

--

Oaes Kuruni

Front-End Software Engineer || Content Writer || Fitness Freak