# react-native-dot-env

> Add .env support to your react-native application without exposing them in JavaScript bundle.

Latest version **0.0.1** (published 2017-05-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-dot-env
pnpm add react-native-dot-env
yarn add react-native-dot-env
bun add react-native-dot-env
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2017-05-02 |
| First published | 2017-05-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Vojtech Bartos |
| Maintainers | vojtechbartos |
| Keywords | react-native, dotenv, env, .env, environment, variables |

## Links

- npm: https://www.npmjs.com/package/react-native-dot-env
- Repository: https://github.com/VojtechBartos/react-native-dot-env
- Issues: https://github.com/VojtechBartos/react-native-dot-env/issues
- npm.io page: https://npm.io/package/react-native-dot-env

## Dependencies (3)

- [plist](https://npm.io/package/plist.md) ^2.0.1
- [dotenv](https://npm.io/package/dotenv.md) ^4.0.0
- [minimist](https://npm.io/package/minimist.md) ^1.2.0

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 0.0.1 (latest) — 2017-05-02

## README

# React Native dotenv

Add `.env` support to your react-native application without including credentials in JavaScript bundle.

[![npm version](https://img.shields.io/npm/v/react-native-dot-env.svg?style=flat-square)](https://www.npmjs.com/package/react-native-dot-env)
[![npm downloads](https://img.shields.io/npm/dt/react-native-dot-env.svg?style=flat-square)](https://www.npmjs.com/package/react-native-dot-env)

Package that loads environment variables from a `.env` file into `process.env`. Credentials are not included in the JavaScript bundle, instead credentials that are bundled in the native app are exposed to the Javascript. It's a much more secure way for you application to access credentials, especially when JavaScript bundles are being remotely downloaded. You can easily use `.env` file and let build process create platform specific configuration files.

**NOTE: Android not supported yet, feel free to contribute :)**

## Installation

```sh
yarn add react-native-dot-env
# or
npm install --save react-native-dot-env
```

### Automatically link

```sh
react-native link react-native-dot-env
```

### Manually link

#### iOS with CocoaPods

Add the following line to your build targets in your `Podfile`

`pod 'RNDotEnv', :path => '../node_modules/react-native-dot-env/ios'`

Then run `pod install`

#### Android

Sorry, Android is not supported yet.

## Getting started

1. Create a new React Native App

  ```sh
  react-native init SimpleApp
  cd SimpleApp
  ```

2. Install the latest version of react-native-dot-env

  ```sh
  yarn add react-native-dot-env
  # or via npm
  # npm install --save react-native-dot-env
  react-native link react-native-dot-env
  ```

3. Create .env file(s) and add them to .gitignore

  ```sh
  echo "API_URL=http://localhost" > .env
  touch ios/.env.plist
  echo ".env*" >> .gitignore
  ```

4. Add newly created `.env.plist` to Xcode project

  - `open ios/SimpleApp.xcodeproj`
  - In Project navigator right click on project `SimpleApp` (root item) and choose `Add Files to "SimpleApp"`
  - Add the newly created `.env.plist` (in MacOS you can show hidden files with `⌘+shift+.`)

  ![Add file](https://raw.githubusercontent.com/VojtechBartos/react-native-dot-env/master/docs/add_file.png)

5. Add `Run script` in Project `Build phases`

  - It has to be before `Copy Bundle resources` (see image)

  ```sh
  node ../node_modules/react-native-dot-env/cli.js -e ../.env -d $SRCROOT
  ```

  ![Build phases](https://raw.githubusercontent.com/VojtechBartos/react-native-dot-env/master/docs/build_phases.png)

6. Add to application source code

  ```js
  import dotenv from 'react-native-dot-env'

  dotenv()

  console.log(process.env)
  ```

7. Run App

  ```sh
  react-native run-ios
  ```

---
_Source: https://npm.io/package/react-native-dot-env · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
