{"name":"dotenv","version":"18.0.7","keywords":["dotenv","env",".env","environment","variables","config","settings","env vars","environment variables","secret-management","secrets"],"license":"BSD-2-Clause","_id":"dotenv@18.0.7","maintainers":[{"name":"scottmotte","email":"scott@scottmotte.com"},{"name":"motdotla","email":"mot@mot.la"},{"name":"motdotenv","email":"mot@dotenv.org"}],"homepage":"https://github.com/motdotla/dotenv#readme","bugs":{"url":"https://github.com/motdotla/dotenv/issues"},"bin":{"dotenv":"dist/index.cjs"},"dist":{"shasum":"ee6bec88c59298d9b218acdf49377f2c110a7698","tarball":"http://registry-npm.ywwl.com/dotenv/download/dotenv-18.0.7.tgz","fileCount":7,"integrity":"sha512-QEvMEF8ca3GNZJJnAbOgxpj5ULhBvnMcURp+XKrtvqFNPgjBvYoswQ0Jl2cO7JzCjxZjJhr9ZuIEhlrRxMft/Q==","signatures":[{"sig":"MEYCIQCeF9LfvDRbpxFe+7YLCSyo8XhHC9MunSJIvxlYKEUT1AIhAPGhJDWb+xqge276BMTxMWTT4G5iesgbmHIxTMxGPSob","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIAs/L1xnObT4GHQV79qyFpz492vQs3snkoMLIrwCfnyYAiEA3fjfaqET2ZgOGb5dfEDCrajPu8aaJTY7gSXDKdbf24k=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":45996,"size":15384,"noattachment":false,"key":"/dotenv/-/dotenv-18.0.7.tgz"},"main":"dist/index.cjs","types":"dist/index.d.ts","browser":{"fs":false},"engines":{"node":">=12"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.cjs","require":"./dist/index.cjs"},"./config":{"types":"./dist/config.d.ts","default":"./dist/config.cjs","require":"./dist/config.cjs"},"./config.js":{"types":"./dist/config.d.ts","default":"./dist/config.cjs","require":"./dist/config.cjs"},"./package.json":"./package.json"},"funding":"https://dotenvx.com","gitHead":"295320751866efa323236c719cdc1b5306fa3de7","scripts":{"lint":"standard","test":"npm run build && npm run lint && npm run dts-check && tap run tests/**/*.js --allow-empty-coverage --disable-coverage --timeout=60000","build":"node scripts/build.js","prepack":"npm run build","release":"standard-version","dts-check":"tsc --project tests/types/tsconfig.json","test:perf":"node scripts/parse-perf.js","prerelease":"npm test","prepublishOnly":"npm pack --dry-run"},"_npmUser":{"name":"motdotla","email":"mot@mot.la"},"repository":{"url":"git://github.com/motdotla/dotenv.git","type":"git"},"_npmVersion":"11.17.0","description":"Loads environment variables from .env file","directories":{},"_nodeVersion":"26.5.0","_hasShrinkwrap":false,"devDependencies":{"tap":"^21.7.4","sinon":"^14.0.1","decache":"^4.6.2","esbuild":"^0.28.1","standard":"^17.0.0","typescript":"^4.8.4","@types/node":"^18.11.3","process-on-spawn":"^1.1.0","standard-version":"^9.5.0"},"_npmOperationalInternal":{"tmp":"tmp/dotenv_18.0.7_1791559310352_0.9733654199945709","host":"s3://npm-registry-packages-npm-production"},"readme":"# dotenv [![NPM version](https://img.shields.io/npm/v/dotenv.svg?style=flat-square)](https://www.npmjs.com/package/dotenv) [![downloads](https://img.shields.io/npm/dw/dotenv)](https://www.npmjs.com/package/dotenv)\n\n<img src=\"https://raw.githubusercontent.com/motdotla/dotenv/master/dotenv.svg\" alt=\"dotenv\" align=\"right\" width=\"200\" />\n\nDotenv is a zero-dependency module that loads environment variables from a `.env` 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](https://12factor.net/config) methodology.\n\n[Watch the tutorial](https://www.youtube.com/watch?v=YtkZR0NFd1g)\n\n&nbsp;\n\n## Usage\n\nInstall it.\n\n```sh\nnpm install dotenv --save\n```\n\nCreate a `.env` file in the root of your project:\n\n```ini\n# .env\nHELLO=\"Dotenv\"\nOPENAI_API_KEY=\"your-api-key-goes-here\"\n```\n\nAs early as possible in your application, import and configure dotenv:\n\n```javascript\n// index.js\nrequire('dotenv').config()\n// or import 'dotenv/config' // for esm\n\nconsole.log(`Hello ${process.env.HELLO}`)\n```\n```sh\n$ node index.js\n◇ injected env (2) from .env\nHello Dotenv\n```\n\nThat's it. `process.env` now has the keys and values you defined in your `.env` file.\n\n&nbsp;\n\n## CLI Usage\n\n**NEW:** Dotenv now has a CLI! Great for your coding agent.\n\n<details>\n<summary>watch the 30 second demo</summary>\n\nhttps://github.com/user-attachments/assets/79395e92-5ce0-430d-b8b5-31631aac25bb\n\n</details>\n\n```javascript\n// index.js\nconsole.log(`Hello ${process.env.HELLO}`)\n```\n\n```\n$ npx dotenv run -- node index.js\n◇ injected env (2) from .env\nHello Dotenv\n```\n\n&nbsp;\n\n## Advanced\n\n<details><summary>ES6</summary><br>\n\nImport with [ES6](#how-do-i-use-dotenv-with-import):\n\n```javascript\nimport 'dotenv/config'\n```\n\n`DOTENV_ENCODING`, `DOTENV_PATH`, `DOTENV_QUIET`, `DOTENV_DEBUG`, `DOTENV_OVERRIDE`, and `DOTENV_FAST` provide defaults for `config()` and `dotenv run`. Options/flags passed directly take precedence, followed by `DOTENV_*`, then the legacy `DOTENV_CONFIG_*` names. Empty values and false values do not fall back.\n\n</details>\n<details><summary>bun</summary><br>\n\n```sh\nbun add dotenv\n```\n\n</details>\n<details><summary>yarn</summary><br>\n\n```sh\nyarn add dotenv\n```\n\n</details>\n<details><summary>pnpm</summary><br>\n\n```sh\npnpm add dotenv\n```\n\n</details>\n<details><summary>deno</summary><br>\n\n```sh\ndeno add dotenv\n```\n\n</details>\n<details><summary>Monorepos</summary><br>\n\nFor monorepos with a structure like `apps/backend/app.js`, put it the `.env` file in the root of the folder where your `app.js` process runs.\n\n```ini\n# app/backend/.env\nS3_BUCKET=\"YOURS3BUCKET\"\nSECRET_KEY=\"YOURSECRETKEYGOESHERE\"\n```\n\n</details>\n<details><summary>Multiline Values</summary><br>\n\nIf you need multiline variables, for example private keys, those are now supported (`>= v15.0.0`) with line breaks:\n\n```ini\nPRIVATE_KEY=\"-----BEGIN RSA PRIVATE KEY-----\n...\nKh9NV...\n...\n-----END RSA PRIVATE KEY-----\"\n```\n\nAlternatively, you can double quote strings and use the `\\n` character:\n\n```ini\nPRIVATE_KEY=\"-----BEGIN RSA PRIVATE KEY-----\\nKh9NV...\\n-----END RSA PRIVATE KEY-----\\n\"\n```\n\n</details>\n<details><summary>Comments</summary><br>\n\nComments may be added to your file on their own line or inline:\n\n```ini\n# This is a comment\nSECRET_KEY=YOURSECRETKEYGOESHERE # comment\nSECRET_HASH=\"something-with-a-#-hash\"\n```\n\nComments begin where a `#` exists, so if your value contains a `#` please wrap it in quotes. This is a breaking change from `>= v15.0.0` and on.\n\n</details>\n<details><summary>Parsing</summary><br>\n\nThe engine which parses the contents of your file containing environment variables is available to use. It accepts a String or Buffer and will return an Object with the parsed keys and values.\n\n```javascript\nconst dotenv = require('dotenv')\nconst buf = Buffer.from('BASIC=basic')\nconst config = dotenv.parse(buf) // will return an object\nconsole.log(typeof config, config) // object { BASIC : 'basic' }\n```\n\n</details>\n<details><summary>Run</summary><br>\n\nUse `dotenv run` to run a command with environment variables from your `.env` file. The `--` separator is optional. Put dotenv options before the command; everything after the command is passed through as its arguments.\n\n```bash\n$ dotenv run node index.js\n◇ injected env (2) from .env\n```\n\nUse `-f` or `--file` to select one or more `.env` files. Separate paths with commas or repeat either flag; files are loaded in the order given. The first value wins unless `--override` is set.\n\n```bash\n$ dotenv run --file .env.local,.env node index.js\n◇ injected env (2) from .env.local, .env\n```\n\nUse `-q` or `--quiet` to suppress the injected env message.\n\n```bash\n$ dotenv run -q node index.js\n```\n\nUse `--override` to overwrite existing environment variables, and `--debug` for debug logging.\n\n```bash\n$ dotenv run --override --debug -- node index.js\n```\n\nThe legacy `DOTENV_CONFIG_*` environment variables formerly used by preload still work as fallbacks for `DOTENV_*`. CLI flags take precedence over both.\n\n```bash\n$ DOTENV_PATH=./.env.local DOTENV_QUIET=true dotenv run -- node index.js\n```\n\nUse `--fast` (or `config({ fast: true })`) for the faster character-scanner parser (~2x). Default remains the classic regex parser.\n\n```bash\n$ dotenv run --fast -- node index.js\n```\n\n```js\nrequire('dotenv').config({ fast: true })\n```\n\nSupported: `DOTENV_PATH`, `DOTENV_ENCODING`, `DOTENV_QUIET`, `DOTENV_DEBUG`, `DOTENV_OVERRIDE`, `DOTENV_FAST`, with matching `DOTENV_CONFIG_*` fallbacks.\n\n</details>\n<details><summary>Variable Expansion</summary><br>\n\nUse [dotenvx](https://github.com/dotenvx/dotenvx) for variable expansion.\n\nReference and expand variables already on your machine for use in your .env file.\n\n```ini\n# .env\nUSERNAME=\"username\"\nDATABASE_URL=\"postgres://${USERNAME}@localhost/my_database\"\n```\n```js\n// index.js\nconsole.log('DATABASE_URL', process.env.DATABASE_URL)\n```\n```sh\n$ dotenvx run --debug -- node index.js\n⟐ injected env (2) from .env · dotenvx@1.59.1\nDATABASE_URL postgres://username@localhost/my_database\n```\n\n</details>\n<details><summary>Command Substitution</summary><br>\n\nUse [dotenvx](https://github.com/dotenvx/dotenvx) for command substitution.\n\nAdd the output of a command to one of your variables in your .env file.\n\n```ini\n# .env\nDATABASE_URL=\"postgres://$(whoami)@localhost/my_database\"\n```\n```js\n// index.js\nconsole.log('DATABASE_URL', process.env.DATABASE_URL)\n```\n```sh\n$ dotenvx run --debug -- node index.js\n⟐ injected env (1) from .env · dotenvx@1.59.1\nDATABASE_URL postgres://yourusername@localhost/my_database\n```\n\n</details>\n<details><summary>Encryption</summary><br>\n\nUse [dotenvx](https://github.com/dotenvx/dotenvx) for encryption.\n\nAdd encryption to your `.env` files with a single command.\n\n```\n$ dotenvx set HELLO Production -f .env.production\n$ echo \"console.log('Hello ' + process.env.HELLO)\" > index.js\n\n$ DOTENV_PRIVATE_KEY_PRODUCTION=\"<.env.production private key>\" dotenvx run -- node index.js\n⟐ injected env (2) from .env.production · dotenvx@1.59.1\nHello Production\n```\n\n[learn more](https://github.com/dotenvx/dotenvx?tab=readme-ov-file#encryption)\n\n</details>\n<details><summary>Multiple Environments</summary><br>\n\nUse [dotenvx](https://github.com/dotenvx/dotenvx) to manage multiple environments.\n\nRun any environment locally. Create a `.env.ENVIRONMENT` file and use `-f` to load it. It's straightforward, yet flexible.\n\n```bash\n$ echo \"HELLO=production\" > .env.production\n$ echo \"console.log('Hello ' + process.env.HELLO)\" > index.js\n\n$ dotenvx run -f=.env.production -- node index.js\nHello production\n> ^^\n```\n\nor with multiple .env files\n\n```bash\n$ echo \"HELLO=local\" > .env.local\n$ echo \"HELLO=World\" > .env\n$ echo \"console.log('Hello ' + process.env.HELLO)\" > index.js\n\n$ dotenvx run -f=.env.local -f=.env -- node index.js\nHello local\n```\n\n[more environment examples](https://dotenvx.com/docs/quickstart/environments?utm_source=github&utm_medium=readme&utm_campaign=motdotla-dotenv&utm_content=docs-environments)\n\n</details>\n<details><summary>Production</summary><br>\n\nUse [dotenvx](https://github.com/dotenvx/dotenvx) for production deploys.\n\nCreate a `.env.production` file.\n\n```sh\n$ echo \"HELLO=production\" > .env.production\n```\n\nEncrypt it.\n\n```sh\n$ dotenvx encrypt -f .env.production\n```\n\nSet `DOTENV_PRIVATE_KEY_PRODUCTION` (found in `.env.keys`) on your server.\n\n```\n$ heroku config:set DOTENV_PRIVATE_KEY_PRODUCTION=value\n```\n\nCommit your `.env.production` file to code and deploy.\n\n```\n$ git add .env.production\n$ git commit -m \"encrypted .env.production\"\n$ git push heroku main\n```\n\nDotenvx will decrypt and inject the secrets at runtime using `dotenvx run -- node index.js`.\n\n</details>\n<details><summary>Syncing</summary><br>\n\nUse [dotenvx](https://github.com/dotenvx/dotenvx) to sync your .env files.\n\nEncrypt them with `dotenvx encrypt -f .env` and safely include them in source control. Your secrets are securely synced with your git.\n\nThis still subscribes to the twelve-factor app rules by generating a decryption key separate from code.\n\n</details>\n<details><summary>More Examples</summary><br>\n\nSee [examples](https://github.com/dotenv-org/examples) of using dotenv with various frameworks, languages, and configurations.\n\n* [nodejs](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-nodejs)\n* [nodejs (debug on)](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-nodejs-debug)\n* [nodejs (override on)](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-nodejs-override)\n* [nodejs (processEnv override)](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-custom-target)\n* [esm](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-esm)\n* [typescript](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-typescript)\n* [typescript parse](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-typescript-parse)\n* [typescript config](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-typescript-config)\n* [webpack](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-webpack)\n* [webpack (plugin)](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-webpack2)\n* [react](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-react)\n* [react (typescript)](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-react-typescript)\n* [express](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-express)\n* [nestjs](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-nestjs)\n* [fastify](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-fastify)\n\n</details>\n\n&nbsp;\n\n## FAQ\n\n<details><summary>Should I commit my `.env` file?</summary><br/>\n\nNo.\n\nUnless you encrypt it with [dotenvx](https://github.com/dotenvx/dotenvx). Then we recommend you do.\n\n</details>\n<details><summary>What about variable expansion?</summary><br/>\n\nUse [dotenvx](https://github.com/dotenvx/dotenvx).\n\n</details>\n<details><summary>Should I have multiple `.env` files?</summary><br/>\n\nWe recommend creating one `.env` file per environment. Use `.env` for local/development, `.env.production` for production and so on. This still follows the twelve factor principles as each is attributed individually to its own environment. Avoid custom set ups that work in inheritance somehow (`.env.production` inherits values from `.env` for example). It is better to duplicate values if necessary across each `.env.environment` file.\n\n> 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>\n> – [The Twelve-Factor App](http://12factor.net/config)\n\nAdditionally, we recommend using [dotenvx](https://github.com/dotenvx/dotenvx) to encrypt and manage these.\n\n</details>\n\n<details><summary>How do I use dotenv with `import`?</summary><br/>\n\nImport `dotenv/config` before modules that read environment variables.\n\n```javascript\n// index.mjs (ESM)\nimport 'dotenv/config'\nimport express from 'express'\n```\n\nThis loads environment variables before the rest of your application modules are initialized. You can also use the CLI to inject them before Node starts:\n\n```bash\ndotenv run -- node index.mjs\n```\n</details>\n\n<details><summary>Can I customize/write plugins for dotenv?</summary><br/>\n\nYes! `dotenv.config()` returns an object representing the parsed `.env` file. This gives you everything you need to continue setting values on `process.env`. For example:\n\n```js\nconst dotenv = require('dotenv')\nconst variableExpansion = require('dotenv-expand')\nconst myEnv = dotenv.config()\nvariableExpansion(myEnv)\n```\n\n</details>\n<details><summary>What rules does the parsing engine follow?</summary><br/>\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- `#` marks the beginning of a comment (unless when the value is wrapped in quotes)\n- empty values become empty strings (`EMPTY=` becomes `{EMPTY: ''}`)\n- inner quotes are maintained (think JSON) (`JSON={\"foo\": \"bar\"}` becomes `{JSON:\"{\\\"foo\\\": \\\"bar\\\"}\"`)\n- whitespace is removed from both ends of unquoted values (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- single and double quoted values are escaped (`SINGLE_QUOTE='quoted'` becomes `{SINGLE_QUOTE: \"quoted\"}`)\n- single and double quoted values maintain whitespace from both ends (`FOO=\"  some value  \"` becomes `{FOO: '  some value  '}`)\n- double quoted values expand new lines (`MULTILINE=\"new\\nline\"` becomes\n\n```\n{MULTILINE: 'new\nline'}\n```\n\n- backticks are supported (`` BACKTICK_KEY=`This has 'single' and \"double\" quotes inside of it.` ``)\n\n</details>\n<details><summary>What about syncing and securing .env files?</summary><br/>\n\nUse [dotenvx](https://github.com/dotenvx/dotenvx) to unlock syncing encrypted .env files over git.\n\n</details>\n<details><summary>How do I specify config options with ES6 import?</summary><br/>\n\nPass options directly to `config()`.\n\n```javascript\n// index.mjs\nimport dotenv from 'dotenv'\n\ndotenv.config({\n  path: '/custom/path/to/.env',\n  debug: true\n})\n\nimport express from 'express'\n```\n\nIf imported modules read environment variables during initialization, use a tiny wrapper file.\n\nCreate `load-env.mjs`:\n\n```javascript\nimport dotenv from 'dotenv'\ndotenv.config({ path: '/custom/path/to/.env', debug: true })\n```\n\nThen in your main file:\n\n```javascript\nimport './load-env.mjs'\nimport express from 'express'\n```\n\n</details>\n<details><summary>What if I accidentally commit my `.env` file to code?</summary><br/>\n\nRemove it, [remove git history](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository) and then install the [git pre-commit hook](https://github.com/dotenvx/dotenvx#pre-commit) to prevent this from ever happening again. \n\n```\nnpm i -g @dotenvx/dotenvx\ndotenvx precommit --install\n```\n\n</details>\n\n<details><summary>What happens to environment variables that were already set?</summary><br/>\n\nBy default, we will never modify any environment variables that have already been set. In particular, if there is a variable in your `.env` file which collides with one that already exists in your environment, then that variable will be skipped.\n\nIf instead, you want to override `process.env` use the `override` option.\n\n```javascript\nrequire('dotenv').config({ override: true })\n```\n\n</details>\n<details><summary>How can I prevent committing my `.env` file to a Docker build?</summary><br/>\n\nUse the [docker prebuild hook](https://dotenvx.com/docs/features/prebuild?utm_source=github&utm_medium=readme&utm_campaign=motdotla-dotenv&utm_content=docs-prebuild).\n\n```bash\n# Dockerfile\n...\nRUN curl -fsS https://dotenvx.sh/ | sh\n...\nRUN dotenvx prebuild\nCMD [\"dotenvx\", \"run\", \"--\", \"node\", \"index.js\"]\n```\n\n</details>\n<details><summary>How come my environment variables are not showing up for React?</summary><br/>\n\nYour React code is run in Webpack, where the `fs` module or even the `process` global itself are not accessible out-of-the-box. `process.env` can only be injected through Webpack configuration.\n\nIf you are using [`react-scripts`](https://www.npmjs.com/package/react-scripts), which is distributed through [`create-react-app`](https://create-react-app.dev/), it has dotenv built in but with a quirk. Preface your environment variables with `REACT_APP_`. See [this stack overflow](https://stackoverflow.com/questions/42182577/is-it-possible-to-use-dotenv-in-a-react-project) for more details.\n\nIf you are using other frameworks (e.g. Next.js, Gatsby...), you need to consult their documentation for how to inject environment variables into the client.\n\n</details>\n<details><summary>Why is the `.env` file not loading my environment variables successfully?</summary><br/>\n\nMost likely your `.env` file is not in the correct place. [See this stack overflow](https://stackoverflow.com/questions/42335016/dotenv-file-is-not-loading-environment-variables).\n\nTurn on debug mode and try again..\n\n```js\nrequire('dotenv').config({ debug: true })\n```\n\nYou will receive a helpful error outputted to your console.\n\n</details>\n<details><summary>Why am I getting the error `Module not found: Error: Can't resolve 'os|path'`?</summary><br/>\n\nYou are using dotenv on the front-end and have not included a polyfill. Webpack < 5 used to include these for you. Do the following:\n\n```bash\nnpm install node-polyfill-webpack-plugin\n```\n\nConfigure your `webpack.config.js` to something like the following.\n\n```js\nrequire('dotenv').config()\n\nconst path = require('path');\nconst webpack = require('webpack')\n\nconst NodePolyfillPlugin = require('node-polyfill-webpack-plugin')\n\nmodule.exports = {\n  mode: 'development',\n  entry: './src/index.ts',\n  output: {\n    filename: 'bundle.js',\n    path: path.resolve(__dirname, 'dist'),\n  },\n  plugins: [\n    new NodePolyfillPlugin(),\n    new webpack.DefinePlugin({\n      'process.env': {\n        HELLO: JSON.stringify(process.env.HELLO)\n      }\n    }),\n  ]\n};\n```\n\nAlternatively, just use [dotenv-webpack](https://github.com/mrsteele/dotenv-webpack) which does this and more behind the scenes for you.\n\n</details>\n\n&nbsp;\n\n## Docs\n\n### SDK\n\nDotenv exposes three functions:\n\n* `config`\n* `parse`\n* `populate`\n\n### Config\n\n`config` will read your `.env` 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 = dotenv.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')`\n\nSpecify a custom path if your file containing environment variables is located elsewhere.\n\n```js\nrequire('dotenv').config({ path: '/custom/path/to/.env' })\n```\nYou can also pass a `URL` object:\n\n```js\nconst fileUrl = new URL('file:///custom/path/to/.env')\n\nrequire('dotenv').config({ path: fileUrl })\n```\n\nBy default, `config` will look for a file called .env in the current working directory.\n\nPass in multiple files as an array, and they will be parsed in order and combined with `process.env` (or `option.processEnv`, if set). The first value set for a variable will win, unless the `options.override` flag is set, in which case the last value set will win.  If a value already exists in `process.env` and the `options.override` flag is NOT set, no changes will be made to that value. \n\n```js  \nrequire('dotenv').config({ path: ['.env.local', '.env'] })\n```\n\n##### quiet\n\nDefault: `false`\n\nSuppress runtime logging message. `dotenv/config` imports and preloads default to `true`; set `DOTENV_QUIET=false` (or `DOTENV_CONFIG_QUIET=false`) in the shell to enable their startup message.\n\n```js\n// index.js\nrequire('dotenv').config({ quiet: false }) // change to true to suppress\nconsole.log(`Hello ${process.env.HELLO}`)\n```\n\n```ini\n# .env\nHELLO=World\n```\n\n```sh\n$ node index.js\nHello World\n```\n\n##### encoding\n\nDefault: `utf8`\n\nSpecify the encoding of your file containing environment variables.\n\n```js\nrequire('dotenv').config({ encoding: 'latin1' })\n```\n\n##### debug\n\nDefault: `false`\n\nTurn on logging to help debug why certain keys or values are not being set as you expect.\n\n```js\nrequire('dotenv').config({ debug: process.env.DEBUG })\n```\n\n##### override\n\nDefault: `false`\n\nOverride any environment variables that have already been set on your machine with values from your .env file(s). If multiple files have been provided in `option.path` the override will also be used as each file is combined with the next. Without `override` being set, the first value wins. With `override` set the last value wins. \n\n```js\nrequire('dotenv').config({ override: true })\n```\n\n##### fast\n\nDefault: `false`\n\nUse the faster character-scanner parser (~2x). Default remains the classic regex parser.\n\n```js\nrequire('dotenv').config({ fast: true })\n```\n\n[Watch the video](https://github.com/user-attachments/assets/8f69bf7a-e7f1-49b9-8650-c0dcb37809e6)\n\n##### processEnv\n\nDefault: `process.env`\n\nSpecify an object to write your environment variables to. Defaults to `process.env` environment variables.\n\n```js\nconst myObject = {}\nrequire('dotenv').config({ processEnv: myObject })\n\nconsole.log(myObject) // values from .env\nconsole.log(process.env) // this was not changed or written to\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 dotenv = require('dotenv')\nconst buf = Buffer.from('BASIC=basic')\nconst config = dotenv.parse(buf) // will return an object\nconsole.log(typeof config, config) // object { BASIC : 'basic' }\n```\n\n#### Options\n\n##### debug\n\nDefault: `false`\n\nTurn on logging to help debug why certain keys or values are not being set as you expect.\n\n```js\nconst dotenv = require('dotenv')\nconst buf = Buffer.from('hello world')\nconst opt = { debug: true }\nconst config = dotenv.parse(buf, opt)\n// expect a debug message because the buffer is not in KEY=VAL form\n```\n\n### Populate\n\nThe engine which populates the contents of your .env file to `process.env` is available for use. It accepts a target, a source, and options. This is useful for power users who want to supply their own objects.\n\nFor example, customizing the source:\n\n```js\nconst dotenv = require('dotenv')\nconst parsed = { HELLO: 'world' }\n\ndotenv.populate(process.env, parsed)\n\nconsole.log(process.env.HELLO) // world\n```\n\nFor example, customizing the source AND target:\n\n```js\nconst dotenv = require('dotenv')\nconst parsed = { HELLO: 'universe' }\nconst target = { HELLO: 'world' } // empty object\n\ndotenv.populate(target, parsed, { override: true, debug: true })\n\nconsole.log(target) // { HELLO: 'universe' }\n```\n\n#### options\n\n##### Debug\n\nDefault: `false`\n\nTurn on logging to help debug why certain keys or values are not being populated as you expect.\n\n##### override\n\nDefault: `false`\n\nOverride any environment variables that have already been set.\n\n&nbsp;\n\n### CLI\n\nThe `dotenv` command is included with the package. Run it with `npx dotenv`, or use `dotenv` directly in npm scripts.\n\n#### run\n\nLoad environment variables from `.env`, then run a command with those variables available.\n\n```sh\nnpx dotenv run [options] -- <command> [args...]\n```\n\n```sh\nnpx dotenv run -- node index.js\nnpx dotenv run -f .env.local -- node index.js\nnpx dotenv run -f .env.local -f .env -- npm test\n```\n\nPut dotenv options before the command. The `--` separator is optional; all arguments after the command are passed to that command.\n\n#### Options\n\n| Option | Description |\n| --- | --- |\n| `-f, --file <paths>` | Load one or more files. Repeat the flag or separate paths with commas. Defaults to `.env`. |\n| `-q, --quiet` | Suppress the injected environment variables message. |\n| `--debug` | Enable debug logging. |\n| `--override` | Overwrite existing environment variables. When loading multiple files, the last value wins. |\n| `--fast` | Use the faster character-scanner parser.<br>[Watch the video](https://github.com/user-attachments/assets/8f69bf7a-e7f1-49b9-8650-c0dcb37809e6) |\n| `-h, --help` | Show help. Also available as `dotenv --help`. |\n\nWithout `--override`, existing environment variables take precedence and the first value found across files wins. With `--override`, values from the files replace existing variables, and later files override earlier ones.\n\nThe CLI forwards the command's exit status. A missing default `.env` is allowed; a missing file explicitly selected with `-f` stops the command from running.\n\n#### Environment defaults\n\nUse these environment variables to set defaults. CLI flags take precedence over them.\n\n| Variable | Default | Description |\n| --- | --- | --- |\n| `DOTENV_PATH` | `.env` | Path to the file to load. |\n| `DOTENV_ENCODING` | `utf8` | File encoding. |\n| `DOTENV_QUIET` | `false` | Suppress the injected environment variables message. |\n| `DOTENV_DEBUG` | `false` | Enable debug logging. |\n| `DOTENV_OVERRIDE` | `false` | Overwrite existing environment variables. |\n| `DOTENV_FAST` | `false` | Use the faster parser. |\n\nThe legacy `DOTENV_CONFIG_*` names remain fallbacks when the corresponding `DOTENV_*` variable is unset. For boolean settings, `false`, `0`, `no`, `off`, and an empty value disable the setting.\n\n&nbsp;\n\n## Related Tools\n\n* [Expand environment variables with dotenv-expand](https://github.com/dotenvx/dotenv-expand)\n* [Cloak your secrets in VS Code](https://marketplace.visualstudio.com/items?itemName=dotenv.dotenv-vscode)\n* [Encrypt your .env files with dotenvx](https://github.com/dotenvx/dotenvx)\n\n&nbsp;\n\n## CHANGELOG\n\nSee [CHANGELOG.md](CHANGELOG.md)\n\n&nbsp;\n\n## Who's using dotenv?\n\n[These npm modules depend on it.](https://www.npmjs.com/browse/depended/dotenv)\n\nProjects that expand it often use the [keyword \"dotenv\" on npm](https://www.npmjs.com/search?q=keywords:dotenv).\n","publish_time":1791559310489,"_cnpm_publish_time":1791559310489,"dist-tags":{"latest":"18.0.9"}}