Number as env var does not work

I have an .env var set like this PUSH_INVITE_DELAY_MINUTES=0 In my code I am calling it like this
const PUSH_INVITE_DELAY_MINUTES = Number(process.env.PUSH_INVITE_DELAY_MINUTES) || 30;
const PUSH_INVITE_DELAY_MINUTES = Number(process.env.PUSH_INVITE_DELAY_MINUTES) || 30;
But PUSH_INVITE_DELAY_MINUTES still returns 30 why?!
6 Replies
utdev
utdev2y ago
If I log process.env.PUSH_INVITE_DELAY_MINUTES I get the correct value set in the env -> 0
Matvey
Matvey2y ago
use ?? instead of ||
utdev
utdev2y ago
This worked
Number.isInteger(Number(process.env.PUSH_INVITE_DELAY_MINUTES))
? Number(process.env.PUSH_INVITE_DELAY_MINUTES)
: 30;
Number.isInteger(Number(process.env.PUSH_INVITE_DELAY_MINUTES))
? Number(process.env.PUSH_INVITE_DELAY_MINUTES)
: 30;
Buut seems long
Matvey
Matvey2y ago
const PUSH_INVITE_DELAY_MINUTES = Number(process.env.PUSH_INVITE_DELAY_MINUTES) ?? 30;
const PUSH_INVITE_DELAY_MINUTES = Number(process.env.PUSH_INVITE_DELAY_MINUTES) ?? 30;
because
0 || 30 // => 30
null || 30 // => 30
0 ?? 30 // => 0
null ?? 30 // => 30
0 || 30 // => 30
null || 30 // => 30
0 ?? 30 // => 0
null ?? 30 // => 30
|| uses == ?? uses ===
utdev
utdev2y ago
that makes sense thank you going to try it out again
sleeprides
sleeprides2y ago
wait seriously??
Want results from more Discord servers?
Add your server