Application environment

The environment should be used to configure your application. When your project is deployed and a new container is started, all the variables defined in your environment are automatically injected into it.

To set an environment variable, there are two ways to do it:
  • In the "Environment" category in your dashboard
  • Using our CLI and the commands scalingo env|env-set|env-unset

Variable alias

You can define aliases of environment variables:

For example:

  • DATABASE_URL -> $SCALINGO_MONGO_URL

In this case the DATABASE_URL becomes an alias of SCALINGO_MONGO_URL value.

Good practices

Using the environment to configure your application is one of twelve good practices defined in the 12 factors.

You should avoid writing any credentials in the files managed by git.

Accessing the environment from your app

The following example is to get the value of the PORT variable.

Ruby

ENV["PORT"]

Go

os.Getenv("PORT")

Javascript

process.env.PORT

Python

os.getenv("PORT")

PHP

$_ENV["PORT"]

Other languages

The process shoul not be really different, refer to the documentation of the standard library of your language.

schedule 15 Sep 2014