I have a simple node with mongo (via mongojs) app that is developed locally and deployed on heroku. In my development environment, i want to use a local instance of mongo, while in production, I would like to use the instance heroku provides to me via "process.env.MONGOLAB_URI".
My current approach is that I would set the datavase url depending on the environment variable, but how do i actually go into production mode? Moreover, how can i configure this so that when i develop on my local machine its development mode, when i upload to heroku its production mode?
app.configure('production', function(){
// ...
databaseUrl = "mydb"; // the default
});
app.configure('development', function(){
// ...
databaseUrl = process.env.MONGOLAB_URI;
});
db = require("mongojs").connect(databaseUrl);
As such, creating an . env file on Heroku isn't a good approach. Instead, you can use its built-in support for environment variables, using heroku config:set <var> <value> or its web UI. Either way, you'll get a regular environment variable.
Go to your project: Open a terminal window and navigate to your project folder: cd my_project. Create the virtual environment: virtualenv venv. Activate the virtual environment: source venv/bin/activate.
Set the NODE_ENV environment variable to "development" on your local environment, and set it to "production" on Heroku. https://devcenter.heroku.com/articles/nodejs#setting-node-env
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With