{"id":16192843,"url":"https://github.com/stanislavt/yamlenv","last_synced_at":"2026-05-07T08:37:12.337Z","repository":{"id":57403014,"uuid":"169910189","full_name":"stanislavt/yamlenv","owner":"stanislavt","description":"Loads environment variables from yaml files for node.js projects","archived":false,"fork":false,"pushed_at":"2019-02-09T23:33:48.000Z","size":45,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-01T17:11:33.414Z","etag":null,"topics":["nodejs","serverless","yaml","yaml-configuration","yaml-variables"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stanislavt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-09T20:26:37.000Z","updated_at":"2024-02-11T10:15:09.000Z","dependencies_parsed_at":"2022-09-18T11:50:54.441Z","dependency_job_id":null,"html_url":"https://github.com/stanislavt/yamlenv","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislavt%2Fyamlenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislavt%2Fyamlenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislavt%2Fyamlenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislavt%2Fyamlenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stanislavt","download_url":"https://codeload.github.com/stanislavt/yamlenv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675609,"owners_count":20977378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nodejs","serverless","yaml","yaml-configuration","yaml-variables"],"created_at":"2024-10-10T08:12:56.191Z","updated_at":"2026-05-07T08:37:12.299Z","avatar_url":"https://github.com/stanislavt.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yamlenv\n\nYamlenv is a zero-dependency module that loads environment variables from a `env.yaml` file into [`process.env`](https://nodejs.org/docs/latest/api/process.html#process_process_env). Storing configuration in the environment separate from code is based on [The Twelve-Factor App](http://12factor.net/config) methodology.\n\n[![BuildStatus](https://travis-ci.com/stanislavt/yamlenv.svg?branch=master)](https://travis-ci.com/stanislavt/yamlenv)\n[![NPM version](https://img.shields.io/npm/v/yamlenv.svg?style=flat-square)](https://www.npmjs.com/package/yamlenv)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n[![Coverage Status](https://img.shields.io/coveralls/stanislavt/yamlenv/master.svg?style=flat-square)](https://coveralls.io/github/stanislavt/yamlenv?branch=coverall-intergration)\n\n## Install\n\n```bash\n# with npm\nnpm install yamlenv\n\n# or with Yarn\nyarn add yamlenv\n```\n\n## Usage\n\nAs early as possible in your application, require and configure yamlenv.\n\n```javascript\nrequire('yamlenv').config()\n```\n\nCreate a `env.yaml` file in the root directory of your project. Add\nenvironment-specific variables on new lines in the form of `NAME: VALUE`.\nFor example:\n\n```dosini\nDB_HOST: localhost\nDB_USER: root\nDB_PASS: s1mpl3\n```\n\nThat's it.\n\n`process.env` now has the keys and values you defined in your `env.yaml` file.\n\n```javascript\nconst db = require('db')\ndb.connect({\n  host: process.env.DB_HOST,\n  username: process.env.DB_USER,\n  password: process.env.DB_PASS\n})\n```\n\n### Preload\n\nYou can use the `--require` (`-r`) command line option to preload yamlenv. By doing this, you do not need to require and load yamlenv in your application code. This is the preferred approach when using `import` instead of `require`.\n\n```bash\n$ node -r yamlenv/config your_script.js\n```\n\nThe configuration options below are supported as command line arguments in the format `yamlenv_config_\u003coption\u003e=value`\n\n```bash\n$ node -r yamlenv/config your_script.js yamlenv_config_path=/custom/path/to/your/env/vars\n```\n\n## Config\n\n_Alias: `load`_\n\n`config` will read your env.yaml file, parse the contents, assign it to\n[`process.env`](https://nodejs.org/docs/latest/api/process.html#process_process_env),\nand return an Object with a `parsed` key containing the loaded content or an `error` key if it failed.  \n\n```js\nconst result = yamlenv.config()\n\nif (result.error) {\n  throw result.error\n}\n\nconsole.log(result.parsed)\n```\n\nYou can additionally, pass options to `config`.\n\n### Options\n\n#### Path\n\nDefault: `path.resolve(process.cwd(), 'env.yaml')`\n\nYou can specify a custom path if your file containing environment variables is\nnamed or located differently.\n\n```js\nrequire('yamlenv').config({path: '/full/custom/path/to/your/env/vars'})\n```\n\n#### Encoding\n\nDefault: `utf8`\n\nYou may specify the encoding of your file containing environment variables\nusing this option.\n\n```js\nrequire('yamlenv').config({encoding: 'base64'})\n```\n\n## Parse\n\nThe engine which parses the contents of your file containing environment\nvariables is available to use. It accepts a String or Buffer and will return\nan Object with the parsed keys and values.\n\n```js\nconst yamlenv = require('yamlenv')\nconst buf = Buffer.from('BASIC: basic')\nconst config = yamlenv.parse(buf) // will return an object\nconsole.log(typeof config, config) // object { BASIC : 'basic' }\n```\n\n### Rules\n\nThe parsing engine currently supports the following rules:\n\n- `BASIC: basic` becomes `{BASIC: 'basic'}`\n- empty lines are skipped\n- lines beginning with `#` are treated as comments\n- empty values become empty strings (`EMPTY: ` becomes `{EMPTY: ''}`)\n- single and double quoted values are escaped (`SINGLE_QUOTE: 'quoted'` becomes `{SINGLE_QUOTE: \"quoted\"}`)\n- new lines are expanded if in double quotes (`MULTILINE: \"new\\nline\"` becomes\n\n```\n{MULTILINE: 'new\nline'}\n```\n- inner quotes are maintained (think JSON) (`JSON: {\"foo\": \"bar\"}` becomes `{JSON:\"{\\\"foo\\\": \\\"bar\\\"}\"`)\n- whitespace is removed from both ends of the value (see more on [`trim`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim)) (`FOO: \"  some value  \"` becomes `{FOO: 'some value'}`)\n\n## FAQ\n\n### Should I commit my `env.yaml` file?\n\nNo. We **strongly** recommend against committing your `env.yaml` file to version\ncontrol. It should only include environment-specific values such as database\npasswords or API keys. Your production database should have a different\npassword than your development database.\n\n### Should I have multiple `env.yaml` files?\n\nNo. We **strongly** recommend against having a \"main\" `env.yaml` file and an \"environment\" `env.yaml` file like `env.test.yaml`. Your config should vary between deploys, and you should not be sharing values between environments.\n\n\u003e In a twelve-factor app, env vars are granular controls, each fully orthogonal to other env vars. They are never grouped together as “environments”, but instead are independently managed for each deploy. This is a model that scales up smoothly as the app naturally expands into more deploys over its lifetime.\n\u003e\n\u003e – [The Twelve-Factor App](http://12factor.net/config)\n\n### What happens to environment variables that were already set?\n\nWe will never modify any environment variables that have already been set. In particular, if there is a variable in your `env.yaml` file which collides with one that already exists in your environment, then that variable will be skipped. This behavior allows you to override all `env.yaml` configurations with a machine-specific environment, although it is not recommended.\n\nIf you want to override `process.env` you can do something like this:\n\n```javascript\nconst fs = require('fs')\nconst yamlenv = require('yamlenv')\nconst envConfig = yamlenv.parse(fs.readFileSync('.env.override'))\nfor (var k in envConfig) {\n  process.env[k] = envConfig[k]\n}\n```\n\n## License\n\nSee [LICENSE](LICENSE)\n\n## Inspiration\n\n[.env](https://github.com/motdotla/dotenv)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstanislavt%2Fyamlenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstanislavt%2Fyamlenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstanislavt%2Fyamlenv/lists"}