Skip to content

LiamMartens/env-file-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Env file docker

Build Status Coverage Status devDependencies Status

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.

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

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'

About

Utility package for handling VAR_FILE type environment variables typically used in Docker images

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published