Q:

Runtime DEV environment variable for React Js (web)

Just like React Native,
When I am testing some web application in development mode I would like to prevent rendering few blocks.
Is there some runtime environment variable like DEV (boolean) in React Js for web?
I wonder if I may be able to do it by setting some cli param like npm start --dev=true?

A:

If your react project is a create-react-app project then there is a special built-in environment variable called NODE_ENV. You can read it from process.env.NODE_ENV. When you run npm start, it is always equal to 'development', when you run npm test it is always equal to 'test', and when you run npm run build to make a production bundle, it is always equal to 'production'.

