Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

config_to_env

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

config_to_env

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

config_to_env

Take a json configuration file, and load it into the running process environment variables before anything in your program runs.

Why would you want to use this?

We have a number of applications that use environment variable configuration overrides, but our deployment system uses json file configs. It's useful for us to simply surface the configuration as environment variables as our app loads.

How to use

The api is extremely simple, and mainly works at require time.

You just need to set a couple of constants to enable the config:

JSON_CONFIG = '/path/to/your/file.json'
require 'config_to_env'

This will load the contents of your json file into the environment of the currently running process. A file like this:

{
    "environment": "test",
    "configuration": {
        "aa": "one",
        "bb": "two"
    },
    "secondary_configuration": {
        "cc": "three"
    }
}

Will be loaded into the environment as the following:

ENVIRONMENT: 'test'
CONFIGURATION_AA: 'one'
CONFIGURATION_BB: 'two'
SECONDARY_CONFIGURATION_CC: 'three'

You can optionally specify particular nodes of the json that you want to include:

JSON_CONFIG_NODES = ['environment', 'configuration']

Which would give you:

ENVIRONMENT: 'test'
AA: 'one'
BB: 'two'

The secondary configuration is dropped entirely.

License

config_to_env is available to everyone under the terms of the MIT open source licence. Take a look at the LICENSE file in the code.

Copyright (c) 2015 BBC

FAQs

Package last updated on 09 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc