{
 "kind": "tool",
 "slug": "dotenv",
 "path": "tools/dotenv/",
 "name": "dotenv",
 "maker": null,
 "density": "full",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Dev workflow and config",
   "tools/dev-workflow/"
  ]
 ],
 "lead": "Keep keys and settings in a .env file.",
 "chips": [
  {
   "label": "Dev workflow and config",
   "path": "tools/dev-workflow/"
  },
  {
   "label": "NPM"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "npm install dotenv"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/motdotla/dotenv"
  },
  {
   "label": "Website",
   "href": "https://github.com/motdotla/dotenv#readme"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "BSD-2-Clause",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met",
   "note": "BSD-2-Clause allows use in paid and closed-source apps.",
   "src": "https://github.com/motdotla/dotenv/blob/master/LICENSE"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Nov 9, 2026",
   "note": "",
   "src": "https://github.com/motdotla/dotenv"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "974 projects",
   "status": "info",
   "sub": "#1 of 299 in its category",
   "note": "Dependency in 974 public GitHub projects set up for AI coding agents that we scanned (15.6%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Docs for agents",
   "status": "yes",
   "sub": "llms.txt",
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": "https://nodejs.org/llms.txt"
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily; card checked Nov 10, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What dotenv does",
   "parts": [
    {
     "t": "prose",
     "text": "dotenv is a small free package for Node.js apps. It reads a plain text file called .env, with lines like PORT=8080, and hands those values to your server code when it starts. Passwords and service keys stay out of the code itself, and each computer or server keeps its own file."
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "Keep service keys out of code",
       "text": "Your assistant puts the database address and service keys in .env, and the code only reads their names, so the secrets never land in your shared code.",
       "idea": false
      },
      {
       "title": "Start any command with your settings",
       "text": "Run a script, a test or a dev server with the values from .env loaded, without changing a line of its code.",
       "idea": false
      },
      {
       "title": "Separate settings for your laptop and the server",
       "text": "Keep one file per place the app runs, for example .env.local for your own machine and .env on the server, and load them in a fixed order.",
       "idea": false
      },
      {
       "title": "Read a settings file into an object",
       "text": "An admin tool or a check before deploy reads a .env file and lists its keys, without changing the running app's settings.",
       "idea": false
      },
      {
       "title": "Test settings that never touch production",
       "text": "Your test setup loads a .env.test file into its own object, so a test run cannot pick up the real database address by mistake.",
       "idea": true
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "dotenv popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "86",
       "of": "/ 100",
       "l": "Gid Score, #25 overall"
      },
      {
       "n": "288M",
       "l": "downloads a week, npm"
      },
      {
       "n": "20.6K",
       "l": "GitHub stars"
      },
      {
       "n": "974",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How dotenv is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "dotenv is a dependency in 974 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (20.0% of the 4,867 JavaScript/TypeScript ones), #1 of 299 in dev workflow and config.",
      "Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 3,987; those are left out of every share on this page.",
      "Projects that use it most often also use tsx (43.8%), TypeScript (83.3%), Zod (56.6%).",
      "It is more common in projects set up for Devin Desktop (25.8%) than for GitHub Copilot (15.6%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "515 projects, 15.7%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "472 projects, 15.6%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      },
      {
       "l": "435 projects, 17.8%",
       "v": "Cursor",
       "path": "agents/cursor/"
      },
      {
       "l": "89 projects, 18.8%",
       "v": "Gemini CLI",
       "path": "agents/gemini-cli/"
      },
      {
       "l": "78 projects, 16.6%",
       "v": "OpenAI Codex",
       "path": "agents/openai-codex/"
      },
      {
       "l": "72 projects, 25.8%",
       "v": "Devin Desktop",
       "path": "agents/devin-desktop/"
      },
      {
       "l": "65 projects, 19.5%",
       "v": "OpenClaw",
       "path": "agents/openclaw/"
      },
      {
       "l": "60 projects, 17.5%",
       "v": "OpenCode",
       "path": "agents/opencode/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 43.8% of its projects",
       "v": "tsx",
       "path": "tools/tsx/"
      },
      {
       "l": "In 83.3% of its projects",
       "v": "TypeScript",
       "path": "tools/typescript/"
      },
      {
       "l": "In 56.6% of its projects",
       "v": "Zod",
       "path": "tools/zod/"
      },
      {
       "l": "In 26.9% of its projects",
       "v": "Express",
       "path": "tools/express/"
      },
      {
       "l": "In 19.0% of its projects",
       "v": "pg",
       "path": "tools/pg/"
      },
      {
       "l": "In 50.4% of its projects",
       "v": "React",
       "path": "tools/react/"
      },
      {
       "l": "In 38.3% of its projects",
       "v": "Lucide React",
       "path": "tools/lucide-react/"
      },
      {
       "l": "In 48.4% of its projects",
       "v": "Tailwind CSS",
       "path": "tools/tailwindcss/"
      }
     ]
    }
   ]
  },
  {
   "id": "profile",
   "nav": "Profile",
   "h2": "dotenv in practice",
   "parts": [
    {
     "t": "h3",
     "text": "Strengths"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "One line of setup, no dependencies",
       "v": "The README describes it as zero-dependency. Setup is a single <code>config()</code> call or <code>import 'dotenv/config'</code> placed early in the app."
      },
      {
       "l": "<code>dotenv run</code> needs no code changes",
       "v": "The CLI injects variables into any command. <code>-f</code> loads several files in order, and <code>-q</code> hides the \"injected env\" message. The README pitches the CLI as \"Great for your coding agent.\""
      },
      {
       "l": "Existing variables are left alone",
       "v": "If a key in <code>.env</code> is already set in the environment, dotenv skips it. You have to opt in to replacing it with <code>override: true</code> or <code>--override</code>."
      },
      {
       "l": "The parser can be called on its own",
       "v": "<code>dotenv.parse()</code> accepts a String or Buffer and returns an object, without touching <code>process.env</code>."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Watch out for"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "No variable expansion or command substitution",
       "v": "<code>${VAR}</code> references and <code>$(cmd)</code> output are not handled by dotenv. The README sends both to dotenvx. Its plugin FAQ shows <code>dotenv-expand</code> applied to the object that <code>config()</code> returns."
      },
      {
       "l": "No encryption, so keep <code>.env</code> out of git",
       "v": "The FAQ says not to commit <code>.env</code> unless you encrypt it with dotenvx. On the website, the creator calls lack of encryption the format's \"biggest security flaw\" and recommends dotenvx."
      },
      {
       "l": "<code>#</code> starts a comment unless quoted",
       "v": "Unquoted values are cut at the first <code>#</code>. The README notes this was a breaking change from <code>&gt;= v15.0.0</code>."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Load .env as early as possible"
    },
    {
     "t": "tabs",
     "label": "Example",
     "items": [
      {
       "tab": "Javascript",
       "code": "// index.js\nrequire('dotenv').config()\n// or import 'dotenv/config' // for esm\n\nconsole.log(`Hello ${process.env.HELLO}`)"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "profile",
   "h2": "More about dotenv",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "Funding",
       "path": "tools/funding/",
       "items": [
        "GitHub Sponsors: https://github.com/motdotla",
        "Own page: https://www.dotenvx.com",
        "4 GitHub sponsors"
       ]
      },
      {
       "title": "Packages around it",
       "items": [
        "express: Web framework",
        "tsx: TypeScript runner",
        "ts-node: TypeScript runner",
        "zod: Schema validation",
        "cors: CORS middleware",
        "axios: HTTP client"
       ]
      },
      {
       "title": "More in Dev workflow and config",
       "path": "tools/dev-workflow/",
       "items": [
        {
         "text": "Husky",
         "path": "tools/husky/"
        },
        {
         "text": "python-dotenv",
         "path": "tools/python-dotenv/"
        },
        {
         "text": "lint-staged",
         "path": "tools/lint-staged/"
        },
        {
         "text": "concurrently",
         "path": "tools/concurrently/"
        },
        {
         "text": "Rich",
         "path": "tools/rich/"
        },
        {
         "text": "Pydantic Settings",
         "path": "tools/pydantic-settings/"
        },
        {
         "text": "cross-env",
         "path": "tools/cross-env/"
        },
        {
         "text": "chalk",
         "path": "tools/chalk/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "dotenv",
       "me": true,
       "facts": [
        "BSD-2-Clause",
        "Gid 86",
        "288M/wk"
       ]
      },
      {
       "name": "dotenvx",
       "why": "Pick dotenvx when you want encrypted .env files you can keep in git, variable expansion or many environments; the dotenv README points there for these.",
       "path": "tools/dotenvx-dotenvx/",
       "facts": []
      },
      {
       "name": "python-dotenv",
       "why": "Pick python-dotenv when your app is written in Python rather than JavaScript.",
       "path": "tools/python-dotenv/",
       "facts": []
      },
      {
       "name": "Varlock",
       "why": "Pick varlock when you want a schema for your .env file that checks each value and keeps secrets away from AI agents.",
       "path": "tools/varlock/",
       "facts": []
      }
     ],
     "more": "Compare dotenv with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "Use the npm package dotenv (pin dotenv@18.0.10) to load settings from .env at server start with import 'dotenv/config' as the first import, add .env to .gitignore, and read keys only from process.env."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Add the package to your project.",
       "code": "npm install dotenv --save",
       "src": "https://github.com/motdotla/dotenv/blob/master/README.md"
      },
      {
       "text": "Create a .env file in the project folder with your settings, one per line.",
       "code": "# .env\nHELLO=\"Dotenv\"\nOPENAI_API_KEY=\"your-api-key-goes-here\"\n",
       "src": "https://github.com/motdotla/dotenv/blob/master/README.md"
      },
      {
       "text": "Load it as the very first thing your app does.",
       "code": "// index.mjs (ESM)\nimport 'dotenv/config'\nimport express from 'express'\n",
       "src": "https://github.com/motdotla/dotenv/blob/master/README.md"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Rules for your agent"
    },
    {
     "t": "rules",
     "label": "Paste into AGENTS.md or CLAUDE.md",
     "text": "## dotenv\n- Call `require('dotenv').config()` or `import 'dotenv/config'` before any module that reads `process.env`. If you pass options and imported modules read variables when they load, put `config()` in a separate wrapper file imported first.\n- To inject variables without editing code, run `dotenv run -- node index.js`.\n- Do not commit `.env`. Keep one file per environment (`.env`, `.env.production`) and do not make files inherit from each other.\n- dotenv does not overwrite variables that are already set. Pass `override: true` or `--override` only when that is intended.\n- Wrap values containing `#` in quotes. Use quoted multiline values or `\\n` for private keys.\n- Do not use `${VAR}` or `$(cmd)` in `.env` and expect dotenv to expand them. The README sends that to dotenvx, and its plugin FAQ shows `dotenv-expand` for expansion.\n"
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "node -r dotenv/config app.js dotenv_config_path=.env.local  (the old preload options)",
       "fix": "dotenv run -f .env.local -- node app.js  (or DOTENV_PATH=.env.local)",
       "why": "dotenv 18 removed the preload options and points to its own run command instead."
      },
      {
       "dont": "import express from 'express' first, then import 'dotenv/config'",
       "fix": "import 'dotenv/config' as the very first import, or a load-env.mjs file imported first",
       "why": "Modules imported earlier read process.env before dotenv has filled it."
      },
      {
       "dont": "Adding dotenv to a Vite or React front-end and reading process.env in browser code",
       "fix": "In a Vite app use import.meta.env and the VITE_ prefix only for values that may be public; keep secrets on the server",
       "why": "Browser code has no process or file access; Vite already loads .env itself and bundles VITE_ values into public files."
      },
      {
       "dont": "SECRET_HASH=something-with-a-#-hash  (unquoted)",
       "fix": "SECRET_HASH=\"something-with-a-#-hash\"",
       "why": "Since version 15 an unquoted"
      },
      {
       "dont": "Expecting .env to replace a value that is already set in the shell or by the host",
       "fix": "Leave it (host settings should win in production), or pass config({ override: true }) on purpose",
       "why": "Values that already exist are skipped by default."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "Should I commit my .env file?",
       "a": "No. Keep it out of git; the README makes an exception only for files encrypted with dotenvx.",
       "evidence": {
        "url": "https://github.com/motdotla/dotenv/blob/master/README.md",
        "quote": "Unless you encrypt it with dotenvx. Then we recommend you do."
       }
      },
      {
       "q": "Why are my values undefined in an ES module app?",
       "a": "Imports run before the rest of your file, so import 'dotenv/config' must be the first import, before modules that read the values.",
       "evidence": {
        "url": "https://github.com/motdotla/dotenv/blob/master/README.md",
        "quote": "This loads environment variables before the rest of your application modules are initialized."
       }
      },
      {
       "q": "A value is already set on my machine. Which one wins?",
       "a": "The one already set. dotenv never replaces it unless you pass override true.",
       "evidence": {
        "url": "https://github.com/motdotla/dotenv/blob/master/README.md",
        "quote": "By default, we will never modify any environment variables that have already been set."
       }
      },
      {
       "q": "My value has a",
       "a": "An unquoted",
       "evidence": {
        "url": "https://github.com/motdotla/dotenv/blob/master/README.md",
        "quote": "Comments begin where a"
       }
      },
      {
       "q": "Can I use it in a paid app?",
       "a": "Yes. BSD-2-Clause allows commercial use; keep the copyright notice with copies of the package.",
       "evidence": {
        "url": "https://github.com/motdotla/dotenv/blob/master/LICENSE",
        "quote": "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met"
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "npm dotenv"
  ],
  [
   "Category",
   "Dev workflow and config"
  ],
  [
   "License",
   "BSD-2-Clause"
  ],
  [
   "Latest version",
   "18.0.7, October 9, 2026"
  ],
  [
   "On GitHub since",
   "July 2013"
  ],
  [
   "Gid Score",
   "86.3"
  ],
  [
   "Rank in category",
   "#1 of 299"
  ],
  [
   "GitHub",
   "motdotla/dotenv"
  ],
  [
   "Last change",
   "Nov 9, 2026"
  ]
 ],
 "good": [
  "Never put the .env file into git. If it happens, remove the file and its history, then add a check that blocks it next time.",
  "It is for code that runs on a server or your computer. Code in the browser cannot read the file this way.",
  "When config() runs it prints a short line with how many values it loaded; pass quiet true to hide it. Version 18 prints it to the error stream."
 ],
 "checked_line": "Read by AgentGid from 5 official pages, card checked Nov 10, 2026; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/motdotla.png"
}