Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/liammartens/env-file-docker
Utility package for handling VAR_FILE type environment variables typically used in Docker images
https://github.com/liammartens/env-file-docker
Last synced: 11 days ago
JSON representation
Utility package for handling VAR_FILE type environment variables typically used in Docker images
- Host: GitHub
- URL: https://github.com/liammartens/env-file-docker
- Owner: LiamMartens
- Created: 2018-03-27T23:25:56.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T01:20:00.000Z (almost 2 years ago)
- Last Synced: 2024-05-01T15:54:38.731Z (8 months ago)
- Language: TypeScript
- Homepage:
- Size: 696 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Env file docker
[![Build Status](https://travis-ci.org/LiamMartens/env-file-docker.svg?branch=master)](https://travis-ci.org/LiamMartens/env-file-docker) [![Coverage Status](https://coveralls.io/repos/github/LiamMartens/env-file-docker/badge.svg?branch=master)](https://coveralls.io/github/LiamMartens/env-file-docker?branch=master) [![devDependencies Status](https://david-dm.org/LiamMartens/env-file-docker/dev-status.svg)](https://david-dm.org/LiamMartens/env-file-docker?type=dev)
This is a utility package to extract environment variables in `Node.js`, taking into account the possibility for `ENV_FILE` type variables as is used a lot in `Docker` containers.
## Configuration
By default the `_FILE` variant will be preferred. This means if a file is set, it will try to load it before falling back on the environment variable as is. This behavior can be altered by setting the `PreferType` as shown below.
```javascript
const envFile = require('env-file-docker');envFile.setPreferType(envFile.PreferTypes.ENV); // the PreferType is envFile.PreferTypes.FILE by default
process.env.HELLO_FILE = '/some/file';
process.env.HELLO = 'world';
console.log(envFile('HELLO', 'default'));
// output will be world, since the environment variable as is is now preferred```
## Usage
```javascript
const envFile = require('env-file-docker');console.log(envFile('HELLO', 'default'));
// output 'default'process.env.HELLO_FILE = '/some/file';
console.log(envFile('HELLO', 'default'));
// output is the content of '/some/file'process.env.HELLO = 'world';
console.log(envFile('HELLO', 'default'));
// output 'world'
```