-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node is casting all env vars to Strings #12126
Comments
Its that, or throw an error.... all env vars ARE strings, by definition. |
I know this has come up a few times. Should we perhaps document that values are coerced to strings? |
@evanlucas all env vars are strings my man. if you want to use different types in your env variables, might I suggest JSON?
in lucas.js you can do:
I have used this pattern to great effect and you can too. As you might understand, this is the same kind of thing a querystrings in URLs, they are always strings. You can use the same pattern to include JSON in query strings. |
@evanlucas I think it could be beneficial for beginners. We hint around the idea in the docs currently. |
I don't see why it's necessary to document this. It's the default behavior for any language tmk. But maybe it wouldn't hurt. |
@ORESoftware Because |
just want to emphasize that process.env is a normal JS object, not just that it looks like one :) I know you know that (duh) but just idk. process.env just happens to have all strings as values. IDK, seems very intuitive to me that it's only strings, this is one of the things that fills up docs but doesn't really help anyone IMO. |
@ORESoftware, it is not a normal object. In addition to casting values to string, Node.js v8 will not allow keys to be symbols:
These behaviors all differ from standard JS object semantics (edit: in other words, |
Having some additional documentation around this would not hurt at all. |
I guess you have already documented that 😄 |
Thank you all for the quick answers :) Fully understand now. I was familiar with the fact that env vars are strings in every other language, I was just not expecting that node would coerce vars to string on runtime as well. Seems that docs are updated too, all good. Thanks! |
Version: v6.10.0
Platform: Mac OS X
Subsystem:
I might have just realised this now, but is it intended that all env vars are casted to Strings by default? See:
Thank you :)
The text was updated successfully, but these errors were encountered: