https://github.com/osdevisnot/dotenv-flexible
flexible dotenv parser
https://github.com/osdevisnot/dotenv-flexible
Last synced: about 1 year ago
JSON representation
flexible dotenv parser
- Host: GitHub
- URL: https://github.com/osdevisnot/dotenv-flexible
- Owner: osdevisnot
- License: mit
- Created: 2019-10-10T17:59:36.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-10-16T00:45:42.000Z (over 6 years ago)
- Last Synced: 2025-02-14T11:07:21.575Z (about 1 year ago)
- Language: TypeScript
- Homepage: https://pkg.fyi/dotenv-flexible
- Size: 13.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dotenv-flexible
> flexible dotenv parser. Think dotenv + dotenv-expand + env overrides (flexibility)
[](https://travis-ci.org/osdevisnot/dotenv-flexible) [](https://coveralls.io/github/osdevisnot/dotenv-flexible?branch=master) [](https://opensource.org/licenses/MIT)
## Installation
```bash
yarn add dotenv-flexible
```
## How it works?
`dotenv-flexible` loads `.env` file into `process.env` with support for environment specific overrides and support for variable expansion/interpolations.
In your code, load and configure dotenv-flexible
```js
require('dotenv-flexible')();
```
then create a `.env` file in project root
```
PORT=8080
HOST=something.com
# optionally add comments to document your options
```
`process.env` now has values you defined in your `.env` file
## Overrides
### overrides using environment files
create a `.env.developement` file in project root with overrides
```
HOST=localhost
```
`process.env` now has values from `.env` and your overrides if `process.env.NODE_ENV === development`
### Overrides from command line.
To override values defined in `.env` and `.env.development`, try passing them from node command line. For example:
```bash
cross-env HOST=klick.js.org node .js
```
`process.env` now has the overrides from command line even if HOST was defined in `.env` or `.env.development`
## Options
### dir
---
default: `process.cwd()`
pass reference to directory if you would like to store `.env` files in a separate config folder.
Note: the dir is resolved from `process.cwd()`
## Contributing
Scaffolded using [`tslib-cli`](https://www.npmjs.com/package/tslib-cli).
Run `yarn` or `npm install` in root folder to setup your project.
### Available Commands:
```bash
yarn build # builds the package
yarn test # run tests for the package
yarn coverage # run tests and generate coverage reports
yarn pub # publish to NPM
yarn format # prettier format
yarn lint # lint pkg files
yarn setup # clean setup
```
## License
**`dotenv-flexible`** is licensed under the [MIT License](http://opensource.org/licenses/MIT).<br>
Documentation is licensed under [Creative Common License](http://creativecommons.org/licenses/by/4.0/).<br>
Created with ♥ by [@osdevisnot](https://github.com/osdevisnot) and [all contributors](https://github.com/osdevisnot/dotenv-flexible/graphs/contributors).