Skip to content

Latest commit

 

History

History
150 lines (95 loc) · 3.15 KB

docs.md

File metadata and controls

150 lines (95 loc) · 3.15 KB

Table of Contents

CLI

This module exposes a CLI that can be run with yarn figaro.

Using the heroku:set command, you can set values from your configuration file all at once:

$ yarn figaro heroku:set -e production

For more information:

$ yarn figaro -h

load

A function that loads env variables into process.env. Internally calls read and merges the result into process.env.

Options

load may be passed an options object containing the following keys:

  • path: The path to the config file (default: './config/application.yml')
  • environment: The string name of the current environment (default: 'development')

Parameters

  • options object Options for the function as specified above.

Examples

// Let's say we've got an application.yml that looks like:
// SOME_VAR: 'FOO'

const Figaro = require('figaro-js')
const path = require('path')

console.log(process.env.SOME_VAR) // -> undefined

Figaro.load({
 path: path.resolve(__dirname, './application.yml')
})

console.log(process.env.SOME_VAR) // -> 'FOO'

*

read

A function that loads env variables from a file and returns an object containing them. The file may contain plain key-value pairs ("shared" variables) or key-values pairs nested under environment keys. The latter will only be loaded if the current environment matches the environment key.

Options

read may be passed an options object containing the following keys:

  • path: The path to the config file (default: './config/application.yml')
  • environment: The string name of the current environment (default: 'development')

Parameters

  • options object Options for the function as specified above.

Examples

// Let's say we've got an application.yml that looks like:
// SOME_VAR: 'FOO'
// development:
//   IS_DEV: true
// production:
//   IS_PROD: true

const Figaro = require('figaro-js')
const path = require('path')

const myEnv = Figaro.read({
   path: path.resolve(__dirname, './application.yml')
})

console.log(myEnv) 
// -> {
//   SOME_VAR: 'FOO',
//   IS_DEV: true
// }

*

requireKeys

A function that checks to make sure certain variables have been loaded into process.env. If they exist in process.env, it returns true; if not, it throws an exception.

Parameters

  • keys ...string The required keys

Examples

if (requireKeys('MY_KEY', 'ANOTHER_KEY')) {
   runProgram()
}

// Above will throw if 'MY_KEY', 'ANOTHER_KEY' are not keys in process.env.

*