Answer the question
In order to leave comments, you need to log in
How to read environment variable from json file?
There is a training project, a backend (Rails), a frontend (React)
There are environment variables in the .env file
These variables have a json file that contains key-value pairs.
For example
ACCOUNTS=[{"name": "some_name", "id": 123456}, {"name": ""some_name2", "id": 12345678}]
How to access an environment variable in react
? answer.
Answer the question
In order to leave comments, you need to log in
1. Using any utility for reading, parsing and importing .env variables into JavaScript. With webpack, dotenv-webpack
2 will be convenient. Using Rails, write to the template:
<script>
window.__data = {
ACCOUNTS: '...',
};
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question