Skip to content

A helper created to generate .env file of accessed ENV variables with its values. It assumes that You have dotenv installed to be able to load ENV variables from .env file.

License

Notifications You must be signed in to change notification settings

Hakier/dotenv-generate-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dotenv-generate-helper

A helper created to generate .env file of accessed ENV variables with its values. It assumes that You have dotenv installed to be able to load ENV variables from .env file.

Installation

Via npm:

$ npm install [-g] dotenv-generate-helper

Command line use

$ collect-env-used-in-file path-to-config-that-uses-env-vars

For example

$ collect-env-used-in-file ./config.js

Import helper

import { DotEnvHelper } from 'dotenv-generate-helper';

Usage

Collect env

import { DotEnvHelper } from 'dotenv-generate-helper';

// tslint:disable:no-console
DotEnvHelper.prepare();

import './config';

console.info('Collected env:', JSON.stringify(DotEnvHelper.accessedEnvMap, null, 2));

Generate env

import { DotEnvHelper } from 'dotenv-generate-helper';

// tslint:disable:no-console
DotEnvHelper.collectEnvUsedInFile('./config')
  .then(() => console.info('.env file generated'))
  .catch(console.error);

Or You can do it like this:

import { DotEnvHelper } from 'dotenv-generate-helper';

DotEnvHelper.prepare();

require('./file1');
require('./file2');
require('./file3');

// tslint:disable:no-console
DotEnvHelper.save()
  .then(() => console.info('.env file generated'))
  .catch(console.error);

About

A helper created to generate .env file of accessed ENV variables with its values. It assumes that You have dotenv installed to be able to load ENV variables from .env file.

Resources

License

Stars

Watchers

Forks

Packages

No packages published