logdown.js
logdown.js copied to clipboard
Environment variables inside React App
Hi,
is there a way to include the NODE_DEBUG environment inside a React App?
As React filters all env variables our that aren't prefixed with REACT_APP_<name>.
best Minh
Hello, @ngmiduc
If you'll provide some *_DEBUG env variable for you react app during build, this will hardcode that value in your code and it won't be possible to change it later at runtime. Do you really want this?
In any case, you can pass REACT_APP_DEBUG during build and then somewhere before running your app just mirror this value in localstorage:
window.localStorage.setItem('debug', process.env.REACT_APP_DEBUG)
Hi
I didn't mean to hard code it into build. I want to run it in development and I think the env variable NODEDEBUG gets filtered out by the react app since it only allows prefixed eng variables to be accessible in the app.
So when I initialize the logdown in some file in the app, it can not access the env Variable to check if the console logs are enabled or disabled.
I created now a separated file that imports logdown and sets the state by a react env variable. Do enable and disable the logs .