https://github.com/bradbyte/react-native-simple-env
Simple react-native environment variables
https://github.com/bradbyte/react-native-simple-env
Last synced: over 1 year ago
JSON representation
Simple react-native environment variables
- Host: GitHub
- URL: https://github.com/bradbyte/react-native-simple-env
- Owner: bradbyte
- License: mit
- Created: 2018-12-11T19:18:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-11T21:14:28.000Z (over 7 years ago)
- Last Synced: 2025-01-30T14:35:14.500Z (over 1 year ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-native-simple-env
Simple environment variables for react-native
## Goals
- [ ] Read environment variables from `.env*` files.
- [ ] Specify which env file to read from (i.e. `.env.staging`).
- [ ] Read environment variables exorted in the shell process.
- [ ] Tests!
## Installation
```bash
// yarn
$ yarn add react-native-simple-env
// npm
$ npm i react-native-simple-env
```
### Usage
RNSE imports any variables defined in the `.env` file, in addition to any system environment variables exported in the shell process that begin with `REACT_NATIVE_`.
```bash
// .env
REACT_NATIVE_API_URL=https://swapi.co/api/
SUCCESS_MESSAGE='It still works'
```
```js
import {env} from "react-native-simple-env";
fetch(env.API_URL)
.then(() => console.log(env.SUCCESS_MESSAGE);
```
To specify which `.env` file to use, set the `RN_ENV` variable to the name of the file you want to use when starting the bundler.
```bash
$ RN_ENV=.env.staging react-native start`
```
### Precendence
1. Variables exported in the terminal process running the metro bundler.
2. Variables defined in `.env*` file.