0

I run the react application using npm start which in package.json is defined as "start": "react-scripts start -o". in the js code I have

const backendUrl = 'hardCodedUrl';

I want this property to be passed as CLI argument. like:

npm start url=newUrl

and read this in the javascript code at runtime to be able to set backendUrl. How Can I do this?

1

1 Answer 1

1

So I visited the link Andy sent and here is how I did it: Because I'm on Windows and using Terminal with PowerShell, run:

$env:REACT_APP_TT_BACKEND_URL = "Thank you Andy"
npm start

In the code

console.log('REACT_APP_TT_BACKEND_URL', process.env.REACT_APP_TT_BACKEND_URL);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.