dotenv-flow icon indicating copy to clipboard operation
dotenv-flow copied to clipboard

no error property set when .env file is not present

Open vineetdigit opened this issue 4 years ago • 2 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"

vineetdigit avatar Jan 14 '21 23:01 vineetdigit

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?

kerimdzhanov avatar Jan 24 '21 19:01 kerimdzhanov

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.

vineetdigit avatar Jan 25 '21 00:01 vineetdigit

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

kerimdzhanov avatar Aug 27 '23 20:08 kerimdzhanov