Skip to content

nlapshin/json-to-env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json-to-env2

Convert json to key-value environment pairs with the ability to use dynamic setpoints

Install

npm i json-to-env2

Usage

Simple example

Script:

  const jsonToEnv = require('json-to-env2');

  const json = {
    deep: {
      env1: 'value1',
      env2: 'value2'
    }
  }

  const env = jsonToEnv(json);

Env:

  DEEP_ENV1=value1
  DEEP_ENV2=value2

Example with the dynamic replacement

Script:

  const jsonToEnv = require('json-to-env2');

  const json = {
    deep: {
      env: '$DYNAMIC_ENV',
    }
  }

  const mapping = {
    $DYNAMIC_ENV: 'value'
  }

  const env = jsonToEnv(json, mapping);

Env:

  DEEP_ENV=value

Example with the dynamic substring replacement

Script:

  const jsonToEnv = require('json-to-env2');

  const json = {
    deep: {
      env: 'prefix-$DYNAMIC_ENV',
    }
  }

  const mapping = {
    $DYNAMIC_ENV: 'value'
  }

  const env = jsonToEnv(json, mapping);

Env:

  DEEP_ENV=prefix-value

Test

npm run test

License

MIT © nlapshin

About

Node JS package which convert json and js to env

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published