I have a React Native application and for some secrets I use react-native-dotenv
. How can I put a variable from my .env
in a script from my package.json
?
For example: "myScript": "run my command with ${myEnvVariable}"
I have a React Native application and for some secrets I use react-native-dotenv
. How can I put a variable from my .env
in a script from my package.json
?
For example: "myScript": "run my command with ${myEnvVariable}"
react-native-dotenv
maintainer here. This library is a babel plugin so it will use environment variables set in your script to compile your Javascript code. However, I'll do my best to answer the question. If you're looking to set environment variables in your script it depends on your operating system.
For unix systems (MacOS / Linux):
"start:development": "NODE_ENV=development MY_VAR=hello npx react-native start",
For Windows Powershell:
"start:development": "Set MY_VAR=hello&& npx react-native start",
The library will not be able to get any values until after the script variables are set. You will have to obtain the environment variables in the code.