Node: Mention case-insensitivity in process.env docs

Created on 18 Oct 2016  Â·  12Comments  Â·  Source: nodejs/node

On Windows OS, environment variables are case-insensitive.

14:46 $ node
> process.env.foo = "lol"
'lol'
> process.env.fOo
'lol'

I think it could be beneficial to make a note about this in the docs.

doc good first issue process test

All 12 comments

It might also be good to add tests for this behaviour to detect platform differences or keep us from accidentally changing anything here.

Would you be interested in writing a pull request to add this yourself? The files to edit should be doc/api/process.md and/or test/parallel/test-process-env.js.

@addaleax I'm not quite sure how to properly test this behavior, as the behavior would likely change depending on which OS you're running the test on. If you have any suggestions, please let me know and I'd be happy to write the test as well.

@oliversalzburg There’s https://github.com/nodejs/node/blob/master/doc/guides/writing_tests.md for generic “How to write a test” things, and you can check for common.isWindows in tests to see whether the test is running on Windows or not. Ideally, you’d check that other OS show the opposite behaviour, to make sure that it’s really only Windows that does this.

@addaleax Ah, sounds good. Thanks for the help :)

@addaleax Is there also a guide for building Node on Windows? Because I'm getting a bunch of linker errors when trying to vcbuild test nosign with Visual Studio 2015.

I am afraid I can only ask @nodejs/platform-windows, but it might help if you have the errors somewhere in a gist or something

Alright, I'll put the information into the PR. Thanks again

For reference, guide for building on Windows: https://github.com/nodejs/node/blob/master/BUILDING.md#windows

So does this mean that process.env is guaranteed to have case-insensitive keys on Windows, even going back to v4? I've hunted in the past for documentation, couldn't find anything, so I just assumed that was the case. Thanks.

@nfischer This behavior is present in Node 4 (and probably earlier as well). We initially noticed this in 4 and assumed it would be something that had changed between 4 and 6. We then realized that it had nothing to do with the version, but with us moving the code from Windows to UNIX.

Also note that this is not really a Node-specific thing. This is simply how Windows handles environment variables.

I understand this is how Windows does env variables. I just wanted to verify that the NodeJS API for accessing those env variables is likewise case-insensitive (as opposed to not guaranteeing if the key is "PATH" or "Path" or "path"). Case insensitive is the only thing that makes sense _to me_, but it's nice to have the guarantee :smile:

I would hate to rely on this being case-insensitive, only to have it crash on someone else's Windows setup because it was undefined behavior. It would also be nice to know if this is intended as a feature in NodeJS going forward (again, I would hate to rely on this if it's likely to be reversed in v7 or v8).

@nfischer The code relies on the GetEnvironmentVariableW Windows API function, which already has case-insensitive behavior. I would consider it extremely unlikely that this behavior would ever change.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fanjunzhi picture fanjunzhi  Â·  3Comments

srl295 picture srl295  Â·  3Comments

cong88 picture cong88  Â·  3Comments

vsemozhetbyt picture vsemozhetbyt  Â·  3Comments

filipesilvaa picture filipesilvaa  Â·  3Comments