env-file-reader

1.0.5 • Public • Published

env-file-reader

stableBuild Status

A simple script for reading (Docker) .env files into a JSON Object

Install

Use npm to install.

npm install env-file-reader --save

Usage

NPM

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.env
VAR_1=my first var
VAR_2=my second var $VAR_3
VAR_3=is cool
var parseEnvFile = require('env-file-reader').parse;
var envs = parseEnvFile('dev.env');
/*
    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 like delimiter[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.

Dependents (1)

Package Sidebar

Install

npm i env-file-reader

Weekly Downloads

26

Version

1.0.5

License

MIT

Unpacked Size

5.08 kB

Total Files

5

Last publish

Collaborators

  • zirror