@agseco/ievj

Interpolation of environment variables in a JSON

Usage no npm install needed!

<script type="module">
  import agsecoIevj from 'https://cdn.skypack.dev/@agseco/ievj';
</script>

README

Build Status npm version

ievj

Interpolation or replacement of environment variables in a JSON.

Why

Because this is just what I needed and I could not find a library that did just this - as opposed using a library that does 1192820282 other things and brings other transitive dependencies.

I decided to publish it in case someone else finds it useful.

How

npm add @agseco/ievj

or

yarn add @agseco/ievj

And then something like this:

const interpolateEnvVars = require('@agseco/ievj');

const myObject = {
  path: '${env.BASE_PATH}/shared/path'
};

process.env.BASE_PATH = '/dev/path';
const interpolated = interpolateEnvVars(myObject);

console.log(interpolated);

Result:

{ path: '/dev/path/shared/path' }

See unit tests for more examples.

How I use it

In case this is what you are looking for. I'm combining it with:

  • dotenv - to automatically populate process.env
  • node-config - to replace some environment variables in my configuration files