3 tricks for solving the `Heroku Application Error`
After deploying your MongoDB site on Heroku you maybe not expecting this error.
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….
After that,
(2) Check your Heroku application’s setting you may forget to put `config vars` its looks like the following photos…
Click the `Reveal config vars`
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.
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……
or,
or,
or,
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…
(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…
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….
Then you will get this tab, see the next photos…..
And click the `connect your application` tab and follow the next steps…..see the next photos
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…
And after set the version, now we are going to copy the `connection string only` which is below this current page. See next photo….
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…..
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…
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:)