dotenv-reader v1.0.1-b
DotEnv-Reader - D.E.R.
a simple, lightweight and zero-dependency package to populate process.env using a .env file
How to install
you can install the package running the following command:
# for npm
npm i dotenv-reader
# for yarn
yarn add dotenv-readerHow to use
At the start of your main file require and init the module
require("dotenv-reader").init();You must create a .env file in the root folder of your project, then, add a key and a value, ONLY ONE PER LINE, in this format: KEY=VALUE.
For example:
PORT=3000
DB_HOST=localhost
DB_USERNAME="main"you can use or not the quotation marks.
Now you can just use process.env.key like this.
console.log(process.env.PORT);
console.log(process.env.DB_HOST);
console.log(process.env.DB_USERNAME);
// Output 3000, localhost, mainInit
init will search and read your .env file, then parse it and populate it to process.env, and return and object with an error key if failed.
const result = der.init();
if (result.error) throw result.error;Params
pathLike
Default: path.resolve(process.cwd(), '.env')
you can specify a custom path if your .env file is not in the root folder of the project
encoding
The encoding for the .env file, by default is "utf-8"
logging
Default: False You can turn on logging to help debug
CastToObj
params
logging
Default: False You can turn on logging to help debug