2

I'd like to be able to launch my client-side React app from another programming language and pass it some command line arguments which would be passed to top level props or a context (or whatever).

I basically want to be able to launch a command like:

npm start inputFile="/path/to/input/file.ext"

And have the inputFile path be passed to my React app. Is this possible? I'm using create-react-app to bootstrap my app.

1

1 Answer 1

3

declare them before the command,
INPUT_FILE="/path/to/input/file.ext" ANOTHER_INPUT_FILE="/another/path/to/input/file.ext" npm start

accessible via process.env.INPUT_FILE
oh the convention is usually uppercase and separated by underscore between words.

or more convenient if you can just put them in .env file
https://create-react-app.dev/docs/adding-custom-environment-variables/#expanding-environment-variables-in-env

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.