4

I want to set MONGOHQ_URL in my sinatra app in order to be able to do this:

uri = URI.parse(ENV['MONGOHQ_URL'])

How do I setup the MONGOHQ_URL?

Bevan
  • 43,618
  • 10
  • 81
  • 133
donald
  • 23,587
  • 42
  • 142
  • 223
  • Is this because you want to go to a different URL on different machines (e.g. production machine, staging machine, development machine), or because you want to go to different URLs based on the deployment mode (e.g. development versus production)? If the former, you have your answer. If the latter...well, we can answer that, too. – Phrogz May 12 '11 at 22:22

2 Answers2

9
  • on Windows: set MONGOHQ_URL=test
  • on Unix (bash): export MONGOHQ_URL=test
  • on Unix (csh): setenv MONGOHQ_URL test
Vasiliy Ermolovich
  • 24,459
  • 5
  • 79
  • 77
  • 2
    In other words, you don't set the environment variable in Sinatra or via Ruby, but rather you set it on the machine you are using outside of Ruby/Sinatra. – Phrogz May 12 '11 at 22:21
  • They are not working in my case. Variables set once and automatically getting removed. I am using Ubuntu 14.04 – Curious Developer May 02 '18 at 10:20
1

In order for your environment variables to always be available to your app, you will need to make sure they get exported whenever a new terminal session launches. It's common to put these in .bashrc for example

export MONGOHQ_URL=https://some.long.secure.url # for example

But for your local development purposes you might want to check out dotenv gem which allows you to store local environment variables in .env file in root of your project. For production, you should be able to Figaro with Sinatra, for more see answer to this question or see readme on the github repo

In general you should always make sure not to commit sensitive config information in your codebase so make sure to add any files like .env or config/application.yml to your .gitignore file.

lacostenycoder
  • 10,623
  • 4
  • 31
  • 48