env-file-reader
A simple script for reading (Docker) .env files into a JSON Object
Install
Use npm to install.
npm install env-file-reader --save
Usage
You can use this package for parsing .env files, regularly used by Docker containers, into a JSON Object. You could, for example, read out the env file to use it in your local non-docker testing by replacing it in some file during built.
Example
#dev.envVAR_1=my first varVAR_2=my second var $VAR_3VAR_3=is cool
var parseEnvFile = parse;var envs = ;/* envs.VAR_1:"my first var", envs.VAR_2:"my second var is cool", envs.VAR_3:"is cool"*/
API
parse(filepath, options = {exclude:[], delimiter:['$','']})
Parses the filepath
env file. options
is optional. Not all options have to be set.
exclude
is an array of strings. It excludes the given variables from the returned object. They will be resolved if you reference them in other environment variables.delimiter
is an array of two strings. All variables for recursive replacement are searched likedelimiter[0]+name+delimiter[1]
.['$','']
is the default, since docker uses it that way.
parseString(filecontent, options = {exclude:[], delimiter:['$','']})
Same as parse
, but takes the file content instead of a file path.
License
MIT, see LICENSE.md for details.