{"id":13515117,"url":"https://github.com/motdotla/dotenv-expand","last_synced_at":"2025-05-12T13:26:09.905Z","repository":{"id":3551490,"uuid":"50004406","full_name":"motdotla/dotenv-expand","owner":"motdotla","description":"Variable expansion for dotenv. Expand variables already on your machine for use in your .env file.","archived":false,"fork":false,"pushed_at":"2025-04-17T02:15:20.000Z","size":604,"stargazers_count":995,"open_issues_count":0,"forks_count":97,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-08T16:03:12.351Z","etag":null,"topics":["dotenv"],"latest_commit_sha":null,"homepage":"https://dotenvx.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/motdotla.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"motdotla","custom":"https://www.dotenvx.com"}},"created_at":"2016-01-20T04:30:26.000Z","updated_at":"2025-05-01T23:14:39.000Z","dependencies_parsed_at":"2024-02-20T04:30:55.949Z","dependency_job_id":"a0881f20-d265-46d4-a584-b159572a408c","html_url":"https://github.com/motdotla/dotenv-expand","commit_stats":{"total_commits":184,"total_committers":29,"mean_commits":6.344827586206897,"dds":"0.32608695652173914","last_synced_commit":"ff7e2efd0d9925c7da82c167ae77d22a6c76e878"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/motdotla%2Fdotenv-expand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/motdotla%2Fdotenv-expand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/motdotla%2Fdotenv-expand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/motdotla%2Fdotenv-expand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/motdotla","download_url":"https://codeload.github.com/motdotla/dotenv-expand/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253336916,"owners_count":21892798,"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":["dotenv"],"created_at":"2024-08-01T05:01:06.470Z","updated_at":"2025-05-12T13:26:09.828Z","avatar_url":"https://github.com/motdotla.png","language":"JavaScript","funding_links":["https://github.com/sponsors/motdotla","https://www.dotenvx.com"],"categories":["Adding Custom Environment Variables","JavaScript","others"],"sub_categories":["Adding Development Environment Variables In `.env`"],"readme":"\u003cdiv align=\"center\"\u003e\n🎉 announcing \u003ca href=\"https://github.com/dotenvx/dotenvx\"\u003edotenvx\u003c/a\u003e. \u003cem\u003e\u003cb\u003eexpansion AND command substitution\u003c/b\u003e, multi-environment, encrypted envs, and more\u003c/em\u003e.\n\u003c/div\u003e\n\n\u0026nbsp;\n\n\u003cdiv align=\"center\"\u003e\n\n**Special thanks to [our sponsors](https://github.com/sponsors/motdotla)**\n\n\u003cbr\u003e\n\u003ca href=\"https://www.warp.dev/?utm_source=github\u0026utm_medium=referral\u0026utm_campaign=dotenv_p_20220831\"\u003e\n  \u003cdiv\u003e\n    \u003cimg src=\"https://res.cloudinary.com/dotenv-org/image/upload/v1661980709/warp_hi8oqj.png\" width=\"230\" alt=\"Warp\"\u003e\n  \u003c/div\u003e\n  \u003cb\u003eWarp is a blazingly fast, Rust-based terminal reimagined to work like a modern app.\u003c/b\u003e\n  \u003cdiv\u003e\n    \u003csup\u003eGet more done in the CLI with real text editing, block-based output, and AI command search.\u003c/sup\u003e\n  \u003c/div\u003e\n\u003c/a\u003e\n\u003cbr\u003e\n\n\u003ca href=\"https://graphite.dev/?utm_source=github\u0026utm_medium=repo\u0026utm_campaign=dotenv\"\u003e\u003cimg src=\"https://res.cloudinary.com/dotenv-org/image/upload/v1744035073/graphite_lgsrl8.gif\" width=\"240\" alt=\"Graphite\" /\u003e\u003c/a\u003e\n\n\u003ca href=\"https://graphite.dev/?utm_source=github\u0026utm_medium=repo\u0026utm_campaign=dotenv\"\u003e\n  \u003cb\u003eGraphite is the AI developer productivity platform helping teams on GitHub ship higher quality software, faster.\u003c/b\u003e\n\u003c/a\u003e\n\u003chr\u003e\n\u003c/div\u003e\n\n# dotenv-expand [![NPM version](https://img.shields.io/npm/v/dotenv-expand.svg?style=flat-square)](https://www.npmjs.com/package/dotenv-expand)\n\n\u003cimg src=\"https://raw.githubusercontent.com/motdotla/dotenv-expand/master/dotenv-expand.png\" alt=\"dotenv-expand\" align=\"right\" width=\"200\" /\u003e\n\nDotenv-expand adds variable expansion on top of [dotenv](http://github.com/motdotla/dotenv). If you find yourself needing to expand environment variables already existing on your machine, then dotenv-expand is your tool.\n\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n[![LICENSE](https://img.shields.io/github/license/motdotla/dotenv-expand.svg)](LICENSE)\n[![codecov](https://codecov.io/gh/motdotla/dotenv-expand/graph/badge.svg?token=pawWEyaMfg)](https://codecov.io/gh/motdotla/dotenv-expand)\n\n## Install\n\n```bash\n# Install locally (recommended)\nnpm install dotenv-expand --save\n```\n\nOr installing with yarn? `yarn add dotenv-expand`\n\n## Usage\n\nCreate a `.env` file in the root of your project:\n\n```dosini\nPASSWORD=\"s1mpl3\"\nDB_PASS=$PASSWORD\n```\n\nAs early as possible in your application, import and configure dotenv and then expand dotenv:\n\n```javascript\nconst dotenv = require('dotenv')\nconst dotenvExpand = require('dotenv-expand')\n\ndotenvExpand.expand(dotenv.config())\n\nconsole.log(process.env) // remove this after you've confirmed it is expanding\n```\n\nThat's it. `process.env` now has the expanded keys and values you defined in your `.env` file.\n\n```\ndotenvExpand.expand(dotenv.config())\n\n...\n\nconnectdb(process.env.DB_PASS)\n```\n\n### Preload\n\n\u003e Note: Consider using [`dotenvx`](https://github.com/dotenvx/dotenvx) instead of preloading. I am now doing (and recommending) so.\n\u003e \n\u003e It serves the same purpose (you do not need to require and load dotenv), has built-in expansion support, adds better debugging, and works with ANY language, framework, or platform. – [motdotla](https://github.com/motdotla)\n\nYou can use the `--require` (`-r`) [command line option](https://nodejs.org/api/cli.html#cli_r_require_module) to preload dotenv \u0026 dotenv-expand. By doing this, you do not need to require and load dotenv or dotenv-expand in your application code. This is the preferred approach when using `import` instead of `require`.\n\n```bash\n$ node -r dotenv-expand/config your_script.js\n```\n\nThe configuration options below are supported as command line arguments in the format `dotenv_config_\u003coption\u003e=value`\n\n```bash\n$ node -r dotenv-expand/config your_script.js dotenv_config_path=/custom/path/to/your/env/vars\n```\n\nAdditionally, you can use environment variables to set configuration options. Command line arguments will precede these.\n\n```bash\n$ DOTENV_CONFIG_\u003cOPTION\u003e=value node -r dotenv-expand/config your_script.js\n```\n\n```bash\n$ DOTENV_CONFIG_ENCODING=latin1 node -r dotenv-expand/config your_script.js dotenv_config_path=/custom/path/to/.env\n```\n\n## Examples\n\nSee [tests/.env.test](https://github.com/motdotla/dotenv-expand/blob/master/tests/.env.test) for simple and complex examples of variable expansion in your `.env`\nfile.\n\n## Documentation\n\n`dotenv-expand` exposes one function:\n\n* expand\n\n### Expand\n\n`expand` will expand your environment variables.\n\n```js\nconst env = {\n  parsed: {\n    BASIC: 'basic',\n    BASIC_EXPAND: '${BASIC}',\n    BASIC_EXPAND_SIMPLE: '$BASIC'\n  }\n}\n\nconsole.log(dotenvExpand.expand(env))\n```\n\n#### Options\n\n##### processEnv\n\nDefault: `process.env`\n\nSpecify an object to write your secrets to. Defaults to `process.env` environment variables.\n\n```js\nconst myEnv = {}\nconst env = {\n  processEnv: myEnv,\n  parsed: {\n    HELLO: 'World'\n  }\n}\ndotenvExpand.expand(env)\n\nconsole.log(myEnv.HELLO) // World\nconsole.log(process.env.HELLO) // undefined\n```\n\n## FAQ\n\n### What rules does the expansion engine follow?\n\nSee a full list of rules [here](https://dotenvx.com/docs/env-file#interpolation).\n\n### How can I avoid expanding pre-existing envs (already in my `process.env`, for example `pas$word`)?\n\nAs of `v12.0.0` dotenv-expand no longer expands `process.env`.\n\nIf you need this ability, use [dotenvx](https://github.com/dotenvx/dotenvx) by shipping an encrypted .env file with your code - allowing safe expansion at runtime.\n\n### How can I override an existing environment variable?\n\nUse [dotenvx](https://github.com/dotenvx/dotenvx) as dotenv-expand does not support this.\n\ndotenv-expand is a separate module (without knowledge of the loading of `process.env` and the `.env` file) and so cannot reliably know what to override.\n\n## Contributing Guide\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md)\n\n## CHANGELOG\n\nSee [CHANGELOG.md](CHANGELOG.md)\n\n## Who's using dotenv-expand?\n\n[These npm modules depend on it.](https://www.npmjs.com/browse/depended/dotenv-expand)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmotdotla%2Fdotenv-expand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmotdotla%2Fdotenv-expand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmotdotla%2Fdotenv-expand/lists"}