{"id":21393701,"url":"https://github.com/itsmichaelbtw/env-agent","last_synced_at":"2026-01-24T17:32:22.089Z","repository":{"id":62388370,"uuid":"555710041","full_name":"itsmichaelbtw/env-agent","owner":"itsmichaelbtw","description":"Easily parse, configure and expand environment variables from .env files at runtime. Supports strict schemas to ensure variables are defined.","archived":false,"fork":false,"pushed_at":"2023-02-21T07:21:30.000Z","size":912,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-21T13:34:48.742Z","etag":null,"topics":["dotenv","env","environment-variables","nodejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/itsmichaelbtw.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-10-22T06:14:14.000Z","updated_at":"2023-12-08T19:31:28.000Z","dependencies_parsed_at":"2023-01-30T18:25:14.682Z","dependency_job_id":null,"html_url":"https://github.com/itsmichaelbtw/env-agent","commit_stats":{"total_commits":74,"total_committers":1,"mean_commits":74.0,"dds":0.0,"last_synced_commit":"4093c62034d2d222c91c228a5690ed45c16e9215"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/itsmichaelbtw/env-agent","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsmichaelbtw%2Fenv-agent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsmichaelbtw%2Fenv-agent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsmichaelbtw%2Fenv-agent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsmichaelbtw%2Fenv-agent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itsmichaelbtw","download_url":"https://codeload.github.com/itsmichaelbtw/env-agent/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsmichaelbtw%2Fenv-agent/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28732603,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-24T10:24:43.181Z","status":"ssl_error","status_checked_at":"2026-01-24T10:24:36.112Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["dotenv","env","environment-variables","nodejs"],"created_at":"2024-11-22T14:13:01.787Z","updated_at":"2026-01-24T17:32:22.074Z","avatar_url":"https://github.com/itsmichaelbtw.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# env-agent\n\nA zero-dependency package for reading environment variables into `process.env` at runtime. Easily parse, load and expand environment variables from `.env` files. Provides sanity checks when parsing `.env` files and ensures all incoming variables are defined before being added to `process.env`.\n\n[![Unit Tests](https://github.com/itsmichaelbtw/env-agent/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/itsmichaelbtw/env-agent/actions/workflows/unit-tests.yml)\n![npm](https://img.shields.io/npm/v/env-agent)\n\n## Installation\n\nnpm:\n```bash\n$ npm install env-agent --save\n```\nyarn:\n```bash\n$ yarn add env-agent\n```\n\n## Usage\n\nEnsure you have a `.env` file in the root of your project. This file should contain all the environment variables you want to use in your project. For example:\n\n```bash\n# .env\nPORT=3000\nNODE_ENV=development\n```\n\nThen, in your project, import the `env-agent` package and call the `load` function:\n\n\u003e It is highly recommended to call the `load` function as early as possible in your project. This will ensure all environment variables are available to your project as soon as possible.\n\n### CommonJS:\n\n```js\nconst envAgent = require('env-agent').default;\n\nenvAgent.load();\n```\n\n### ES6:\n\n```js\nimport envAgent from 'env-agent';\n\nenvAgent.load();\n\n// {\n//   PORT: 3000,\n//   NODE_ENV: 'development'\n// }\n```\nNow all the environment variables defined in your `.env` file are available in `process.env`.\n\n## API\n\n### `load([, options])`\n\nloads the environment variables defined in your `.env` file. This function should be called as early as possible in your project.\n\n#### `options`\n\n| Option    | Type    | Default       | Description                                                                            |\n|-----------|---------|---------------|----------------------------------------------------------------------------------------|\n| silent    | boolean | true          | When attempting to load the .env file, specify whether errors should be thrown or not. |\n| strict    | boolean | false         | Ensures variables are defined before being added to `process.env`.                     |\n| path      | string  | process.cwd() | The path to the `.env` file.                                                           |\n| expand    | string  | 'none'        | Choose to expand variables defined in your .env file.                                  |\n| overwrite | boolean | false         | Overwrite existing environment variables.                                              |\n| encoding  | string  | 'utf8'        | The encoding of the `.env` file when reading.                                          |\n| debug     | boolean | false         | Show debug messages when loading the `.env` file.                                      |\n| template  | string  | undefined     | Define a template to validate the `.env` file against.                                 |\n\n```js\nenvAgent.load({\n    silent: false,\n    debug: true\n});\n```\n\n### `parse(file)`\n\nParses the input and returns an object containing the environment variables. \n\n```js\nconst env = envAgent.parse(`\n    PORT=3000\n    NODE_ENV=development\n`);\n\n// or\n\nconst env = envAgent.parse(Buffer.from('PORT=3000\\nNODE_ENV=development'));\n```\n\n### `expand(variables, expansionMode)`\n\nChoose to expand variables defined in your .env file. It is recommened to expand variables when calling envAgent.load(). Select the expansion mode that best suits your needs.\n\n- `none` - No expansion will be performed.\n- `project` - Expand variables defined in the .env file (does not expand current process.env variables).\n- `machine` - Expand variables defined on your machine's environment (expands current process.env variables).\n\n```js\nenvAgent.load({ expand: \"project\" }) // variables will automatically expand\n\n// or\n\nconst variables = envAgent.load();\n\nenvAgent.expand(variables, \"project\"); // variables will expand\n```\n\nYou can denote a variable to be expanded by using the following syntax:\n\n- `$VARIABLE`\n- `${VARIABLE}`\n\n```bash\n# .env\nPORT=3000\nNODE_ENV=development\nHOST=localhost\nURL=http://${HOST}:$PORT # HOST and PORT will be expanded\n```\n\n```js\nenvAgent.load({ expand: \"project\" });\n\n// {\n//   PORT: 3000,\n//   NODE_ENV: 'development',\n//   HOST: 'localhost',\n//   URL: 'http://localhost:3000'\n// }\n```\n\n### `get(key)`\n\nRetrieve a single environment variable from `process.env`.\n\n### `set(key, value[, overwrite])`\n\nSets a single environment variable in `process.env`. Ensures configuration rules are followed:\n\n- If `strict` is `true`, the variable must be defined before being added to `process.env`.\n- If `overwrite` is `false`, the variable must not already exist in `process.env`.\n- If `expand` is `true`, the variable will be overwritten with the value.\n\n### `delete(key)`\n\nDeletes a single environment variable from `process.env`.\n\n## CHANGELOG\n\nSee [CHANGELOG.md](CHANGELOG.md)\n\n## LICENSE\n\nSee [LICENSE](LICENSE)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsmichaelbtw%2Fenv-agent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitsmichaelbtw%2Fenv-agent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsmichaelbtw%2Fenv-agent/lists"}