score:17

Accepted answer

as per the docs, we cannot override node_env, but there is a room to create our own custom variables starting with react_app_. so i configured to look as below:

reference: https://facebook.github.io/create-react-app/docs/adding-custom-environment-variables

"staging": "concurrently -k  \"npm:staging-server\" \"cross-env react_app_environment='staging' port=3003 react-scripts start\"",

and inside my ui application, i can fetch its value by consoling it like this: console.log('react_app_environment => ', process.env.react_app_environment);

score:1

use cross-env in front of node_env.

npm i -g cross-env
"staging": "concurrently -k  \"npm:staging-server\" \"cross-env node_env='staging' port=3003 react-scripts start\"",

score:2

easiest approach is to add it directly in your command:

"scripts": {
    "start": "./node_modules/.bin/nodemon server.js",
    "start:prod": "node_env=prod node server.js",
  },

score:5

i build the build with react_app_stage and use it in my application as process.env.react_app_stage.

"scripts": {
    "analyze": "source-map-explorer 'build/static/js/*.js'",
    "build-css": "node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/",
    "watch-css": "npm run build-css && node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/ --watch --recursive",
    "start-js": "react-scripts start",
    "start": "react_app_stage=local npm-run-all -p watch-css start-js",
    "build": "npm run build-css && react-scripts build",
    "build-dev": "react_app_stage=dev react-scripts build",
    "build-prod": "react_app_stage=prod react-scripts build",
    "build-qa": "react_app_stage=qa react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },

Related Query

More Query from same tag