How important is .env in React?

0

I'm developing a website in React and I came across the .env file and it contains the following script NODE_PATH=./src for what would be its importance in React? Because my server only worked when I include this file in the project directory. I need an answer that is clear on the subject, unwarranted answers will be flagged.

    
asked by anonymous 15.06.2018 / 15:59

1 answer

1

The .env file is the file where the environment variables of your application are stored.

Somewhere in your application it should be using the 'NODE_PATH' variable and so it did not work. In this file you can also add other important settings if you need to centralize them.

You can get these environment variables by: process.env.SUA_VARIAVEL

Let's suppose you want to type in only one place the name of your application, so you do not need to change all the files you've created. In this case you could add the following in your .env:

MY_APP_TITLE = My APP Name

and there in your js file you get this data with process.env.MY_APP_TITLE

    
15.06.2018 / 16:05