# obj2env

> Create files storing environment variables by using objects.

Latest version **1.0.5** (published 2020-08-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install obj2env
pnpm add obj2env
yarn add obj2env
bun add obj2env
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2020-08-10 |
| First published | 2017-05-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Bloggify |
| Maintainers | ionicabizau |
| Keywords | environment, stringify, file, object, array |

## Links

- npm: https://www.npmjs.com/package/obj2env
- Repository: https://github.com/Bloggify/obj2env
- Homepage: https://github.com/Bloggify/obj2env#readme
- Issues: https://github.com/Bloggify/obj2env/issues
- npm.io page: https://npm.io/package/obj2env

## Dependencies (2)

- [typpy](https://npm.io/package/typpy.md) ^2.3.12
- [streamp](https://npm.io/package/streamp.md) ^3.0.2

## 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

- 1.0.5 (latest) — 2020-08-10
- 1.0.4 — 2020-08-09
- 1.0.3 — 2017-12-06
- 1.0.2 — 2017-12-06
- 1.0.1 — 2017-12-06
- 1.0.0 — 2017-05-11

## README

<!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. -->


















# obj2env

 [![Version](https://img.shields.io/npm/v/obj2env.svg)](https://www.npmjs.com/package/obj2env) [![Downloads](https://img.shields.io/npm/dt/obj2env.svg)](https://www.npmjs.com/package/obj2env)







> Create files storing environment variables by using objects.






Use [`dotenv`](https://www.npmjs.com/package/dotenv) for loading an `.env` file in your application.












## :cloud: Installation

```sh
# Using npm
npm install --save obj2env

# Using yarn
yarn add obj2env
```













## :clipboard: Example



```js
var { item, toArray, toFile } = require("obj2env")

console.log(item("PORT", 8080))
// => PORT=8080

console.log(toArray({
    PORT: 8080
  , NODE_ENV: "production"
}))
// => [ 'PORT=8080', 'NODE_ENV=production' ]

// Will create a file named `.env` in this directory
toFile({
    PORT: 8080
  , NODE_ENV: "production"
}, __dirname, err => {
    err && console.error(err)
    // The .env file contains:
    // PORT=8080
    // NODE_ENV=production
})
```











## :question: Get Help

There are few ways to get help:



 1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.
 2. For bug reports and feature requests, open issues. :bug:





## :memo: Documentation


### `envToItem(name, value)`
Converts the pair of name and value into a string.

#### Params

- **String** `name`: The environment variable name.
- **String** `value`: The environment variable value.

#### Return
- **String** The stringified pair.

### `envToArray(obj)`
Converts an object of environment variables into an array.

#### Params

- **Object** `obj`: The object containing environment variables to stringify.

#### Return
- **Array** An array of stringified pairs.

### `toFile(obj, dir, cb)`
Create a file named `.env` in the specified directory.

#### Params

- **Object** `obj`: The object containing environment variables to stringify.
- **String** `dir`: The directory where to create the `.env` file (default: the current directory).
- **Function** `cb`: The callback function.

#### Return
- **Stream** The writable stream.














## :yum: How to contribute
Have an idea? Found a bug? See [how to contribute][contributing].
















## :dizzy: Where is this library used?
If you are using this library in one of your projects, add it in this list. :sparkles:

 - `obj2env-cli`











## :scroll: License

[MIT][license] © [Bloggify][website]






[license]: /LICENSE
[website]: https://bloggify.org
[contributing]: /CONTRIBUTING.md
[docs]: /DOCUMENTATION.md

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