0
votes

on deploying meanapp , mongodb is working fine on local node server.js but when i deploy to heroku it showing error

2019-06-04T02:49:12.401001+00:00 heroku[web.1]: State changed from up to starting

2019-06-04T02:49:13.706279+00:00 heroku[web.1]: Stopping all processes with SIGTERM

2019-06-04T02:49:13.800926+00:00 heroku[web.1]: Process exited with status 143

2019-06-04T02:49:17.993509+00:00 heroku[web.1]: Starting process with command node server.js

2019-06-04T02:49:20.786431+00:00 app[web.1]: mongodb+srv://username:[email protected]

/test?retryWrites=true 2019-06-04T02:49:20.803912+00:00 app[web.1]: app listening at 40970

2019-06-04T02:49:20.972565+00:00 app[web.1]: database error MongoNetworkError: connection 4 to cluster0-shard-00-01-dlcak.mongodb.net:27017 closed

2019-06-04T02:49:20.973723+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: TypeError: callback is not a function

2019-06-04T02:49:20.973725+00:00 app[web.1]: at $initialConnection.$initialConnection.then (/app/node_modules/mongoose/lib/connection.js:638:13)

2019-06-04T02:49:20.973810+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

2019-06-04T02:49:20.973880+00:00 app[web.1]: (node:4) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

2019-06-04T02:49:21.758205+00:00 heroku[web.1]: State changed from starting to up

2

2 Answers

1
votes

I got the solution while searching,

  1. go to mongodb atlas

  2. click security -> Network Access -> ADD IP ADDRESS -> Choose allow access from anywhere and save

  3. click connect and get your application to your code and paste to your application.

0
votes

How is it configured on Heroku?

Use https://elements.heroku.com/addons/mongolab -- for reference

Add

const mongo_url = process.env.MONGO_URI || "YOUR_URL_HERE";

to your code