Pass env vars to react via webpack

# webpack.config.js.. here you can read the process.env.variables from nodeconst PROCESS_ENV_NODE_ENV = process.env.NODE_ENV ? process.env.NODE_ENV : 'local';module.exports = {
new webpack.DefinePlugin({
The you can read them in react by accessing`process.env.REACT_APP_ENVIRONMENT`Note 1: In my current version, it didn't work with variable named PROCESS_ENV
Note 2: the prefix process.env is mandatory for the variable




Software Engineer @ London []

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Going TypeStack with NX Monorepo and Docker (Part 2)

RxJS From Scratch

Computer Science: Recursion

Backstage with “new” keyword in JS

Global HTTP error catching in Angular 4.3+

Pure Node.js HTTP Server

Build a NodeJS cinema API Gateway and deploying it to Docker (part 4)

[Javascript] How to check string is Empty?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Elvis Ciotti

Elvis Ciotti

Software Engineer @ London []

More from Medium

“Flat” Promises for Reactive Code

Getting started with React Query

React + TypeScript + ESLint + Prettier

Create-React-App with TypeScript, ESLint, Prettier