Skip to content

Inject environment variables to string with bash syntax!

License

Notifications You must be signed in to change notification settings

kimxogus/inject-env

Repository files navigation

inject-env

Inject environment variables to string

npm version npm downloads

Build Status

Installation

  • npm
npm install inject-env
  • yarn
yarn add inject-env

Usage

import injectEnv from 'inject-env'

const bashProfilePath = injectEnv('${HOME}/.bash_profile');   // /your/home/.bash_profile

const apiURL = injectEnv('${HTTP_PROXY}/api');                // http://proxy.url/api

// Without default value
injectEnv('${NODE_ENV}');             // undefined

// With default value
injectEnv('${NODE_ENV:-development}')  // development

// With default value
injectEnv('${NODE_ENV-development}')   // development if unset

// With substitution value
injectEnv('${NODE_ENV:+development}')  // development if value set

// With substitution value
injectEnv('${NODE_ENV+development}')   // development if set

// Does not work without '{' and '}' characters!
injectEnv('$NODE_ENV');               // $NODE_ENV

injectEnv(['${NODE_ENV}', '${PWD}'])  // [undefined, '/your/pwd']

injectEnv({a: '${NODE_ENV}', b: '${PWD}'}) // {a: undefined, b: '/your/pwd'}

About

Inject environment variables to string with bash syntax!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published