Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kimxogus/inject-env
Inject environment variables to string with bash syntax!
https://github.com/kimxogus/inject-env
environment-variables nodejs
Last synced: about 17 hours ago
JSON representation
Inject environment variables to string with bash syntax!
- Host: GitHub
- URL: https://github.com/kimxogus/inject-env
- Owner: kimxogus
- License: mit
- Created: 2017-06-08T14:01:47.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-03T12:43:37.000Z (over 5 years ago)
- Last Synced: 2024-11-04T21:48:22.341Z (about 2 months ago)
- Topics: environment-variables, nodejs
- Language: JavaScript
- Homepage:
- Size: 60.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# inject-env
> Inject environment variables to string[![npm version](https://img.shields.io/npm/v/inject-env.svg)](https://npmjs.org/package/inject-env)
[![npm downloads](https://img.shields.io/npm/dm/inject-env.svg)](https://npmjs.org/package/inject-env)[![Build Status](https://travis-ci.org/kimxogus/inject-env.svg?branch=master)](https://travis-ci.org/kimxogus/inject-env)
## Installation
- npm
```bash
npm install inject-env
```- yarn
```bash
yarn add inject-env
```## Usage
```js
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_ENVinjectEnv(['${NODE_ENV}', '${PWD}']) // [undefined, '/your/pwd']
injectEnv({a: '${NODE_ENV}', b: '${PWD}'}) // {a: undefined, b: '/your/pwd'}
```