Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thalesfp/node-env-yml
Environment variable loader using yml files
https://github.com/thalesfp/node-env-yml
env environment-variables nodejs yaml yml
Last synced: 2 months ago
JSON representation
Environment variable loader using yml files
- Host: GitHub
- URL: https://github.com/thalesfp/node-env-yml
- Owner: thalesfp
- Created: 2020-03-07T19:04:18.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-17T07:20:30.000Z (about 1 year ago)
- Last Synced: 2024-10-11T10:39:58.638Z (2 months ago)
- Topics: env, environment-variables, nodejs, yaml, yml
- Language: JavaScript
- Homepage:
- Size: 242 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node Env YML
[![CI](https://github.com/thalesfp/node-env-yml/actions/workflows/node.js.yml/badge.svg)](https://github.com/thalesfp/node-env-yml/actions/workflows/node.js.yml)Environment variable loader using yml files.
## Installation
```bash
npm install env-yml
```## Usage
Declaring variables in a file (eg. .app.yml):
```yaml
# Variables available in any environment
DATABASE_HOST: '127.0.0.1'
DATABASE_PORT: '5432'# Variables available in development environment
development:
DATABASE_USER: 'user-dev'# Variables available in test environment
test:
DATABASE_USER: 'user-test'
```Reading the file:
```javascript
const loadEnv = require('env-yml');loadEnv();
console.log(process.env.DATABASE_HOST)
console.log(process.env.DATABASE_PORT)
console.log(process.env.DATABASE_USER)
```## Parameters
Optional configuration params:
| name | description | default value |
|---|---|---|
| path | path to yml file | .app.yml |
| encoding | encoding of yml file | utf8 |
| env | force environment section | development |Usage:
```javascript
const loadEnv = require('env-yml');loadEnv({
path: 'myapp.yml',
encoding: 'latin1',
env: 'staging',
});
```