You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried IS_BOOL=true but when I console.log(process.env.IS_BOOL); it displays a string "true" but it should be casted to boolean true.
I also tried IS_NUM=10 and it is a string "10" but it should be numeric 10.
I also tried IS_FLOAT=10.5 and it is a string "10.5" but it should be a float 10.5.
The text was updated successfully, but these errors were encountered:
ajcastro
changed the title
Boolean env variables are not casted to boolean
Boolean and Numeric env variables are not casted properly
Jun 9, 2021
Environment variables are strings though, not numbers or booleans. That is true independent of this project and even of Node.js.
The function of this library is to load predefined env vars (strings) from a .env file into process.env (collection of strings).
Actually Node.js won't even let you assign any other type of value (besides a string) to a property of process.env, since that value will be converted to a string:
Refer to the other similar issues for discussion of ways to deal with casting env vars to other (not string) value types: #51#77
There are some robust solutions offered, but the simple solution is just code that casts/parses each string according to its intended type:
Thanks for the response. I came from Laravel/PHP where variables are parsed by default, so I thought it was the same. Someone from the quasar community answered that I can use this https://github.com/niftylettuce/dotenv-parse-variables to make it work.
I tried
IS_BOOL=true
but when Iconsole.log(process.env.IS_BOOL);
it displays a string"true"
but it should be casted to booleantrue
.I also tried
IS_NUM=10
and it is a string"10"
but it should be numeric10
.I also tried
IS_FLOAT=10.5
and it is a string"10.5"
but it should be a float10.5
.The text was updated successfully, but these errors were encountered: