How the Node module 'envfile' handles comments

suggestion
Tags: #<Tag:0x00007f805e6e61b8>

#1

I’m using the envfile Noe module and am seeing it interpret comment lines. If my .env file contains something like this:

# This is a comment with = in the middle
PARAM1=VALUE1

then calling envfile2json ends up creating this JSON object:

{"# This is a comment with":"in the middle","PARAM1":"VALUE1"}

This seems to be because the comment has the ‘=’ character in it. I wouldn’t expect a parse of a .env file to interpret a comment as an env defining line.

Other libraries and languages just ignore comments, but I’m not sure how envfile could ignore a comment and maintain round-tripping (so .env to json to .env). Maybe using the “//” convention so that the .env file above would produce {"//":"# This is a comment with = in the middle","PARAM1":"VALUE1"}, but even then if I’m using envfile to get the env definitions to use them in something else, then I still end up with an interpretation of a comment.


#2

There doesn’t seem to be any standard for .env files. Heroku’s documentation for them doesn’t seem to include comment support, which is what ours is based off. Happy to have comment support added.

Pull request would target:


#3

Pull request created - https://github.com/bevry/envfile/pull/9


#4

PR Merged on 2018-01-25:

And released to v2.2.0: