Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

process.env environment variable undefined

I am trying to access an environment variable through process.env in my React/Typescript code, but it's returning undefined. I am able to access NODE_ENV though.

console.log(process.env.CURRENT_URL) // prints "undefined" on browser
console.log(process.env.NODE_ENV) // prints "development" on browser

CURRENT_URL is present in windows environment variable.

Why is process.env.NODE_ENV is accessible but not the other variable?

like image 387
user968437 Avatar asked Jul 18 '26 17:07

user968437


1 Answers

This is your answer, from the official create-react-app docs.

Summary:
By default you will have NODE_ENV defined for you, and any other environment variables starting with REACT_APP_.

So prepend REACT_APP_ to all your env variables e.g. REACT_APP_CURRENT_URL.
That should work!

like image 134
MwamiTovi Avatar answered Jul 21 '26 09:07

MwamiTovi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!