Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 469
donald Avatar asked Dec 28 '22 20:12

donald


2 Answers

  • on Windows: set MONGOHQ_URL=test
  • on Unix (bash): export MONGOHQ_URL=test
  • on Unix (csh): setenv MONGOHQ_URL test
like image 185
Vasiliy Ermolovich Avatar answered Jan 16 '23 05:01

Vasiliy Ermolovich


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.

like image 38
lacostenycoder Avatar answered Jan 16 '23 05:01

lacostenycoder