kerimdzhanov / dotenv-flow

Loads environment variables from .env.[development|test|production][.local] files for Node.js® projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

no error property set when .env file is not present

vineetdigit opened this issue · comments

Upon calling .config(), dotenv sets an error property in the returned object when .env is not present.

var result = require("dotenv").config();

// result.error property is set when .env is not present in the root directory of the node project

dotenv-flow does not set an error property, and instead it only has an empty "parsed" object.

var result = require("dotenv-flow).config();

// restult.error is not present, but result.parsed is an empty object

It would be nice to have a consistent behavior as "dotenv"

Hey @vineetdigit,

The reason for such difference in behavior is that in "dotenv-flow", we may not have .env file (while having i.e. .env.development, .env.production, etc.,), so we can't consider it as an error.

On the other hand, if we have no .env* files at all, this behavior might be reasonable.

What are your thoughts?

My exact thoughts. As long as at least one of the files is present and it was successfully parsed, then result.parsed property will contain parsed values and result.error property should be undefined. Otherwise, result.error property will be set but the result.parsed will be undefined or an empty object.

I see. Thanks for your thoughts and the idea in general!