donald
donald

Reputation: 23767

Set an environment variable in a Sinatra app?

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?

Upvotes: 4

Views: 5451

Answers (2)

lacostenycoder
lacostenycoder

Reputation: 11236

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.

Upvotes: 1

Vasiliy Ermolovich
Vasiliy Ermolovich

Reputation: 24637

  • on Windows: set MONGOHQ_URL=test
  • on Unix (bash): export MONGOHQ_URL=test
  • on Unix (csh): setenv MONGOHQ_URL test

Upvotes: 9

Related Questions