0

I've deployed an app to heroku and I want to make this app recognize platform information by itself. That is,

var dburi = '';
if( is_heroku )
  dburi = process.env.MONGOLAB_URI;
else
  dburi = 'mongodb://xxx'; 

Is there a way to get recognition (flag?) "is_heroku"?

Thanks!

1 Answer 1

1

Just use a guard. It doesn't matter whether or not you're on Heroku:

var dburi = process.env.MONGOLAB_URI || 'mongodb://xxx';

That way, if you're in an environment that specifies MONGOLAB_URI, you use it, and if not you fall back to some default (for local development, for instance).

Another benefit of this is that you can point your app to connect to whichever db you like, eg:

MONGOLAB_URI='mongodb://some-db-in-the-cloud' node server.js
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I forgot this usage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.