How to set environment variable in React JS..?

To set it for current process execution, just edit your package.json file and modify the "build" script as follows:

"scripts": {
"start": "react-scripts start",
"build": "set \"CI=false\" && react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject" }

This will set CI environment variable to "false". Now you can execute the build command with CI variable set:

npm run build

check out this package dotenv,

  1. create a new file .env in your working directory

  2. install dotenv by npm install dotenv

  3. add this to your app require('dotenv').config()

  4. in that file write process.env.CI = false

  5. add .env to your .gitignore [if using git]

  6. restart your app.

OR run this CI=false npm run build


Your question title is very different to what is happening in the description.

To use environment variables in React, they must be prefixed with REACT_APP_.

For example, the following will be picked up by a React application:

REACT_APP_API_URL=/api

Whereas this won't:

API_URL=/api

For more, please see the official documentation: