0

While developing a React app, I needed to use some environment variables. The way to do it is by using this syntax:

REACT_APP_NOT_SECRET_CODE=abcdef npm start

see reference

My first question is: How does that work? I don't know this linux thing, what's happening behind the scenes?

My second question is: How to I make more scalable? say I have file that looks like that

MY_VAR_1=123
MY_VAR_2=23332
MY_VAR_3=3232

How do I inject it to the npm process? I tried

cat .env | npm start 

But it doesn't work

I guess after I understand the linux syntax I get be in a better position to use a file instead of inline data.

Thanks

YardenST
  • 247
  • 3
  • 9

1 Answers1

1

Regarding the first question- it’s just setting an environment variable for the program.
You could achieve the same by first exporting the variable.
Regarding the second question- you have to source (either use the keyword ‘source’ or a dot) the file for it to affect the current session.

easiest might be to add ‘export’ before each line in the file, then

. file
program
Dani_l
  • 4,943