Parch
Parch

Reputation: 17

Connect app locally to local Mongo db and on heroku to Mongo Atlas

I am trying to do the following:

So far I have only connected it to Mongo Atlas and I dont know how to do both of them at the same time.

enter image description here

Upvotes: 0

Views: 65

Answers (1)

pingPong
pingPong

Reputation: 26

Use enviroment varialbles.
Define env variables in your project using .env.
e.g in .env file use

DEVELOPMENT=true

and check if it's local or Heroku

if (process.env.DEVELOPMENT) {
 conenctToLocalDB();
}else{
  connectToAtlas();
}

Upvotes: 1

Related Questions