Skip to content

env() removes capitalization from camel case variable names #345

@pownkel

Description

@pownkel

In the update to v16, it looks like the behavior of env() changed to convert all env variable names to lowercase. Here's an example to illustrate:

process.env.camelCaseArg = 'value';
process.env.lowercasearg = 'value';

const envArgs = yargs().env().argv;

console.log(`lower case: ${envArgs.lowercasearg}`);
console.log(`camel case: ${envArgs.camelCaseArg}`);
console.log(`camel case variable with lower case name: ${envArgs.camelcasearg}`);

Running this on v15.4.0 prints

lower case: value
camel case: value
camel case variable with lower case name: undefined

While in v16.0.0 and later, the same code prints

lower case: value
camel case: undefined
camel case variable with lower case name: value

Updating to v16 broke some of our code as our camel case env variables were no longer found under their original names. I'm not sure whether the change was intentional, but the API documentation for .env() still shows camel case env variable names in the argv object, which is misleading.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions