1.2.0 • Published 4 years ago

environment-variable-reader v1.2.0

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

Environment Variable Reader

Install

npm i environment-variable-reader

Usage

Create a file named .env in your root directory. And fill it with content like:

DB_NAME=thedb
DB_HOST=localhost

Then in your code you can access DB_NAME like so:

const { getEnvironmentVariable } = require('environment-variable-reader');

const dbName = getEnvironmentVariable('DB_NAME');

Default value

If your .env file does not have DB_USER and we want DB_USER to have a default value than we can do it like this:

const dbUser = getEnvironmentVariable('DB_USER', 'root');

Otherwise if we don't specify a default value and that environment variable does not not exist, then getEnvironmentVariable will throw error.

1.2.0

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago