Environment variables as strings

I’m not sure if this is a bug, or just a clarification:


These appear to be strings.

if (process.env.CIRCLECI === 'true') { // This passes

if (process.env.CIRCLECI === true) { // This fails

I kinda expected both to work.

1 Like

Hi there,

Thanks for pointing this out. I’m sure this will help clear up another user’s confusion. It looks like this is just how NodeJS handles environment environment variables. Even environment variables saved as numbers will match as strings in NodeJS when using === to compare.

Hope this helps!


1 Like

You are absolutely correct. This is what I get for not doing my research

The process.env object forces all of its properties to be of type string, since environment variables must always be strings.

This appears to be a very core part of OS operations that I was not aware of, libc stores all env variables as strings as well.

char * getenv (const char *name)

Ref: http://stackoverflow.com/a/10265271/335583
Ref: Environment Access (The GNU C Library)