npm

Need private packages and team management tools?Check out npm Orgs. »

env-file-reader

1.0.4 • Public • Published

env-file-reader

stable

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.

install

npm i env-file-reader

Downloadsweekly downloads

15

version

1.0.4

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability