# env-create

> Read in a .env.json file that contains valid JSON and assign top level properties to environment variables

Latest version **1.1.4** (published 2022-03-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install env-create
pnpm add env-create
yarn add env-create
bun add env-create
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2022-03-09 |
| First published | 2019-03-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 0 |
| Unpacked size | 17.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Tod Gentille |
| Maintainers | rolias |
| Keywords | dotenv, env, .env, .env.json, environment, variables, json, jason, load, create, config, auth, secrets, load |

## Links

- npm: https://www.npmjs.com/package/env-create
- Repository: https://github.com/Rolias/env-create
- Homepage: https://github.com/Rolias/env-create#readme
- Issues: https://github.com/Rolias/env-create/issues
- npm.io page: https://npm.io/package/env-create

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.1.4 (latest) — 2022-03-09
- 1.1.3 — 2022-03-07
- 1.1.1 — 2019-04-17
- 1.1.0 — 2019-04-17
- 1.0.9 — 2019-03-19
- 1.0.8 — 2019-03-14
- 1.0.7 — 2019-03-14
- 1.0.4 — 2019-03-14
- 1.0.3 — 2019-03-07
- 1.0.0 — 2019-03-06

## README

# env-create

Reads in a valid JSON file and creates environment variables for every top level object found in the resulting object, **unless** an environment variable of that name already exists. It will not overwrite existing environment variables. It will only create environment variables for the top level objects.  

[![NPM version](https://img.shields.io/npm/v/env-create.svg?style=flat-square)](~https://www.npmjs.com/package/env-create~) 
![BuildStatus](https://img.shields.io/travis/Rolias/env-create.svg)
[![Maintainability](https://api.codeclimate.com/v1/badges/51a7c2ddffdc29ba06b5/maintainability)](https://codeclimate.com/github/Rolias/env-create/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/51a7c2ddffdc29ba06b5/test_coverage)](https://codeclimate.com/github/Rolias/env-create/test_coverage)
[![Inline docs](https://inch-ci.org/github/Rolias/env-create.svg?branch=master)](https://github.com/Rolias/env-create)
<!-- How to do it using img.shield.io [![Test Coverage](https://img.shields.io/codeclimate/coverage/Rolias/env-create.svg)](https://codeclimate.com/github/Rolias/env-create/test_coverage)
-->

## Installation  

`npm i env-create --save`  
Although at this point you should have made `--save` your default

## Basic usage

Let's assume you have a `.env.json` at the root level of your project with the following contents

```JSON
{
  "secret1": {
      "client_id": "123445",
  },
  "secret2": {
    "access_token": "reallylongtoken",
  },
}
```

Somewhere early in your code before you need the environment variables you add  

```javascript
require('env-create').load() 
const firstSecret = JSON.parse(process.env.secret1);
const secondSecret = JSON.parse(process.env.secret2);
```

The `load()` method will create a process environment variable for every top level object in the the default `.env.json` file located at the root of your project. The `load()` method optionally takes a JSON object with properties for `path`, and `encoding`. Both properties are optional.  The function returns an array of messages. If an environment variable already existed and would have been overwritten there were will be a message letting you know that.

## Option usage

Using a relative path to go up one folder out of your project and into an ENV_VARS folder to get the file named `gsweet.env.json`

```javascript
require('env-create').load({
    path: "../ENV_VARS/gsweet.env.json", 
    encode: "utf8"))  
const firstSecret = JSON.parse(process.env.secret1);
const secondSecret = JSON.parse(process.env.secret2);
```

You can also use an absolute path which is likely preferred if you store authentication data that is required among multiple projects

```javascript
const result = require('env-create').load({
  path: "/User/yourUserName/ENV_VARS/gsweet.env.json",
  encode: "utf8"))
```

## Acknowledgement

Inspired by [dotenv](https://github.com/motdotla/dotenv)

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