市场夺宝奇兵
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

692 lines
23 KiB

  1. <div align="center">
  2. 🎉 announcing <a href="https://github.com/dotenvx/dotenvx">dotenvx</a>. <em>run anywhere, multi-environment, encrypted envs</em>.
  3. </div>
  4. &nbsp;
  5. <div align="center">
  6. **Special thanks to [our sponsors](https://github.com/sponsors/motdotla)**
  7. <a href="https://tuple.app/dotenv">
  8. <div>
  9. <img src="https://res.cloudinary.com/dotenv-org/image/upload/w_1000,ar_16:9,c_fill,g_auto,e_sharpen/v1756831704/github_repo_sponsorship_gq4hvx.png" width="600" alt="Tuple">
  10. </div>
  11. <b>Tuple, the premier screen sharing app for developers on macOS and Windows.</b>
  12. </a>
  13. <hr>
  14. </div>
  15. # dotenv [![NPM version](https://img.shields.io/npm/v/dotenv.svg?style=flat-square)](https://www.npmjs.com/package/dotenv)
  16. <img src="https://raw.githubusercontent.com/motdotla/dotenv/master/dotenv.svg" alt="dotenv" align="right" width="200" />
  17. Dotenv 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.
  18. [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
  19. [![LICENSE](https://img.shields.io/github/license/motdotla/dotenv.svg)](LICENSE)
  20. [![codecov](https://codecov.io/gh/motdotla/dotenv-expand/graph/badge.svg?token=pawWEyaMfg)](https://codecov.io/gh/motdotla/dotenv-expand)
  21. * [🌱 Install](#-install)
  22. * [🏗️ Usage (.env)](#%EF%B8%8F-usage)
  23. * [🌴 Multiple Environments 🆕](#-manage-multiple-environments)
  24. * [🚀 Deploying (encryption) 🆕](#-deploying)
  25. * [📚 Examples](#-examples)
  26. * [📖 Docs](#-documentation)
  27. * [❓ FAQ](#-faq)
  28. * [⏱️ Changelog](./CHANGELOG.md)
  29. ## 🌱 Install
  30. ```bash
  31. npm install dotenv --save
  32. ```
  33. You can also use an npm-compatible package manager like yarn, bun or pnpm:
  34. ```bash
  35. yarn add dotenv
  36. ```
  37. ```bash
  38. bun add dotenv
  39. ```
  40. ```bash
  41. pnpm add dotenv
  42. ```
  43. ## 🏗️ Usage
  44. <a href="https://www.youtube.com/watch?v=YtkZR0NFd1g">
  45. <div align="right">
  46. <img src="https://img.youtube.com/vi/YtkZR0NFd1g/hqdefault.jpg" alt="how to use dotenv video tutorial" align="right" width="330" />
  47. <img src="https://simpleicons.vercel.app/youtube/ff0000" alt="youtube/@dotenvorg" align="right" width="24" />
  48. </div>
  49. </a>
  50. Create a `.env` file in the root of your project (if using a monorepo structure like `apps/backend/app.js`, put it in the root of the folder where your `app.js` process runs):
  51. ```dosini
  52. S3_BUCKET="YOURS3BUCKET"
  53. SECRET_KEY="YOURSECRETKEYGOESHERE"
  54. ```
  55. As early as possible in your application, import and configure dotenv:
  56. ```javascript
  57. require('dotenv').config()
  58. console.log(process.env) // remove this after you've confirmed it is working
  59. ```
  60. .. [or using ES6?](#how-do-i-use-dotenv-with-import)
  61. ```javascript
  62. import 'dotenv/config'
  63. ```
  64. ES6 import if you need to set config options:
  65. ```javascript
  66. import dotenv from 'dotenv'
  67. dotenv.config({ path: '/custom/path/to/.env' })
  68. ```
  69. That's it. `process.env` now has the keys and values you defined in your `.env` file:
  70. ```javascript
  71. require('dotenv').config()
  72. // or import 'dotenv/config' if you're using ES6
  73. ...
  74. s3.getBucketCors({Bucket: process.env.S3_BUCKET}, function(err, data) {})
  75. ```
  76. ### Multiline values
  77. If you need multiline variables, for example private keys, those are now supported (`>= v15.0.0`) with line breaks:
  78. ```dosini
  79. PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
  80. ...
  81. Kh9NV...
  82. ...
  83. -----END RSA PRIVATE KEY-----"
  84. ```
  85. Alternatively, you can double quote strings and use the `\n` character:
  86. ```dosini
  87. PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nKh9NV...\n-----END RSA PRIVATE KEY-----\n"
  88. ```
  89. ### Comments
  90. Comments may be added to your file on their own line or inline:
  91. ```dosini
  92. # This is a comment
  93. SECRET_KEY=YOURSECRETKEYGOESHERE # comment
  94. SECRET_HASH="something-with-a-#-hash"
  95. ```
  96. Comments 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.
  97. ### Parsing
  98. The 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.
  99. ```javascript
  100. const dotenv = require('dotenv')
  101. const buf = Buffer.from('BASIC=basic')
  102. const config = dotenv.parse(buf) // will return an object
  103. console.log(typeof config, config) // object { BASIC : 'basic' }
  104. ```
  105. ### Preload
  106. > Note: Consider using [`dotenvx`](https://github.com/dotenvx/dotenvx) instead of preloading. I am now doing (and recommending) so.
  107. >
  108. > It serves the same purpose (you do not need to require and load dotenv), adds better debugging, and works with ANY language, framework, or platform. – [motdotla](https://github.com/motdotla)
  109. You can use the `--require` (`-r`) [command line option](https://nodejs.org/api/cli.html#-r---require-module) to preload dotenv. By doing this, you do not need to require and load dotenv in your application code.
  110. ```bash
  111. $ node -r dotenv/config your_script.js
  112. ```
  113. The configuration options below are supported as command line arguments in the format `dotenv_config_<option>=value`
  114. ```bash
  115. $ node -r dotenv/config your_script.js dotenv_config_path=/custom/path/to/.env dotenv_config_debug=true
  116. ```
  117. Additionally, you can use environment variables to set configuration options. Command line arguments will precede these.
  118. ```bash
  119. $ DOTENV_CONFIG_<OPTION>=value node -r dotenv/config your_script.js
  120. ```
  121. ```bash
  122. $ DOTENV_CONFIG_ENCODING=latin1 DOTENV_CONFIG_DEBUG=true node -r dotenv/config your_script.js dotenv_config_path=/custom/path/to/.env
  123. ```
  124. ### Variable Expansion
  125. Use [dotenvx](https://github.com/dotenvx/dotenvx) to use variable expansion.
  126. Reference and expand variables already on your machine for use in your .env file.
  127. ```ini
  128. # .env
  129. USERNAME="username"
  130. DATABASE_URL="postgres://${USERNAME}@localhost/my_database"
  131. ```
  132. ```js
  133. // index.js
  134. console.log('DATABASE_URL', process.env.DATABASE_URL)
  135. ```
  136. ```sh
  137. $ dotenvx run --debug -- node index.js
  138. [dotenvx@0.14.1] injecting env (2) from .env
  139. DATABASE_URL postgres://username@localhost/my_database
  140. ```
  141. ### Command Substitution
  142. Use [dotenvx](https://github.com/dotenvx/dotenvx) to use command substitution.
  143. Add the output of a command to one of your variables in your .env file.
  144. ```ini
  145. # .env
  146. DATABASE_URL="postgres://$(whoami)@localhost/my_database"
  147. ```
  148. ```js
  149. // index.js
  150. console.log('DATABASE_URL', process.env.DATABASE_URL)
  151. ```
  152. ```sh
  153. $ dotenvx run --debug -- node index.js
  154. [dotenvx@0.14.1] injecting env (1) from .env
  155. DATABASE_URL postgres://yourusername@localhost/my_database
  156. ```
  157. ### Syncing
  158. You need to keep `.env` files in sync between machines, environments, or team members? Use [dotenvx](https://github.com/dotenvx/dotenvx) to encrypt your `.env` files and safely include them in source control. This still subscribes to the twelve-factor app rules by generating a decryption key separate from code.
  159. ### Multiple Environments
  160. Use [dotenvx](https://github.com/dotenvx/dotenvx) to generate `.env.ci`, `.env.production` files, and more.
  161. ### Deploying
  162. You need to deploy your secrets in a cloud-agnostic manner? Use [dotenvx](https://github.com/dotenvx/dotenvx) to generate a private decryption key that is set on your production server.
  163. ## 🌴 Manage Multiple Environments
  164. Use [dotenvx](https://github.com/dotenvx/dotenvx)
  165. Run any environment locally. Create a `.env.ENVIRONMENT` file and use `--env-file` to load it. It's straightforward, yet flexible.
  166. ```bash
  167. $ echo "HELLO=production" > .env.production
  168. $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
  169. $ dotenvx run --env-file=.env.production -- node index.js
  170. Hello production
  171. > ^^
  172. ```
  173. or with multiple .env files
  174. ```bash
  175. $ echo "HELLO=local" > .env.local
  176. $ echo "HELLO=World" > .env
  177. $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
  178. $ dotenvx run --env-file=.env.local --env-file=.env -- node index.js
  179. Hello local
  180. ```
  181. [more environment examples](https://dotenvx.com/docs/quickstart/environments)
  182. ## 🚀 Deploying
  183. Use [dotenvx](https://github.com/dotenvx/dotenvx).
  184. Add encryption to your `.env` files with a single command. Pass the `--encrypt` flag.
  185. ```
  186. $ dotenvx set HELLO Production --encrypt -f .env.production
  187. $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
  188. $ DOTENV_PRIVATE_KEY_PRODUCTION="<.env.production private key>" dotenvx run -- node index.js
  189. [dotenvx] injecting env (2) from .env.production
  190. Hello Production
  191. ```
  192. [learn more](https://github.com/dotenvx/dotenvx?tab=readme-ov-file#encryption)
  193. ## 📚 Examples
  194. See [examples](https://github.com/dotenv-org/examples) of using dotenv with various frameworks, languages, and configurations.
  195. * [nodejs](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-nodejs)
  196. * [nodejs (debug on)](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-nodejs-debug)
  197. * [nodejs (override on)](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-nodejs-override)
  198. * [nodejs (processEnv override)](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-custom-target)
  199. * [esm](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-esm)
  200. * [esm (preload)](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-esm-preload)
  201. * [typescript](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-typescript)
  202. * [typescript parse](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-typescript-parse)
  203. * [typescript config](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-typescript-config)
  204. * [webpack](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-webpack)
  205. * [webpack (plugin)](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-webpack2)
  206. * [react](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-react)
  207. * [react (typescript)](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-react-typescript)
  208. * [express](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-express)
  209. * [nestjs](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-nestjs)
  210. * [fastify](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-fastify)
  211. ## 📖 Documentation
  212. Dotenv exposes four functions:
  213. * `config`
  214. * `parse`
  215. * `populate`
  216. ### Config
  217. `config` will read your `.env` file, parse the contents, assign it to
  218. [`process.env`](https://nodejs.org/docs/latest/api/process.html#process_process_env),
  219. and return an Object with a `parsed` key containing the loaded content or an `error` key if it failed.
  220. ```js
  221. const result = dotenv.config()
  222. if (result.error) {
  223. throw result.error
  224. }
  225. console.log(result.parsed)
  226. ```
  227. You can additionally, pass options to `config`.
  228. #### Options
  229. ##### path
  230. Default: `path.resolve(process.cwd(), '.env')`
  231. Specify a custom path if your file containing environment variables is located elsewhere.
  232. ```js
  233. require('dotenv').config({ path: '/custom/path/to/.env' })
  234. ```
  235. By default, `config` will look for a file called .env in the current working directory.
  236. Pass 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.
  237. ```js
  238. require('dotenv').config({ path: ['.env.local', '.env'] })
  239. ```
  240. ##### quiet
  241. Default: `false`
  242. Suppress runtime logging message.
  243. ```js
  244. // index.js
  245. require('dotenv').config({ quiet: false }) // change to true to suppress
  246. console.log(`Hello ${process.env.HELLO}`)
  247. ```
  248. ```ini
  249. # .env
  250. .env
  251. ```
  252. ```sh
  253. $ node index.js
  254. [dotenv@17.0.0] injecting env (1) from .env
  255. Hello World
  256. ```
  257. ##### encoding
  258. Default: `utf8`
  259. Specify the encoding of your file containing environment variables.
  260. ```js
  261. require('dotenv').config({ encoding: 'latin1' })
  262. ```
  263. ##### debug
  264. Default: `false`
  265. Turn on logging to help debug why certain keys or values are not being set as you expect.
  266. ```js
  267. require('dotenv').config({ debug: process.env.DEBUG })
  268. ```
  269. ##### override
  270. Default: `false`
  271. Override 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.
  272. ```js
  273. require('dotenv').config({ override: true })
  274. ```
  275. ##### processEnv
  276. Default: `process.env`
  277. Specify an object to write your environment variables to. Defaults to `process.env` environment variables.
  278. ```js
  279. const myObject = {}
  280. require('dotenv').config({ processEnv: myObject })
  281. console.log(myObject) // values from .env
  282. console.log(process.env) // this was not changed or written to
  283. ```
  284. ### Parse
  285. The engine which parses the contents of your file containing environment
  286. variables is available to use. It accepts a String or Buffer and will return
  287. an Object with the parsed keys and values.
  288. ```js
  289. const dotenv = require('dotenv')
  290. const buf = Buffer.from('BASIC=basic')
  291. const config = dotenv.parse(buf) // will return an object
  292. console.log(typeof config, config) // object { BASIC : 'basic' }
  293. ```
  294. #### Options
  295. ##### debug
  296. Default: `false`
  297. Turn on logging to help debug why certain keys or values are not being set as you expect.
  298. ```js
  299. const dotenv = require('dotenv')
  300. const buf = Buffer.from('hello world')
  301. const opt = { debug: true }
  302. const config = dotenv.parse(buf, opt)
  303. // expect a debug message because the buffer is not in KEY=VAL form
  304. ```
  305. ### Populate
  306. The 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.
  307. For example, customizing the source:
  308. ```js
  309. const dotenv = require('dotenv')
  310. const parsed = { HELLO: 'world' }
  311. dotenv.populate(process.env, parsed)
  312. console.log(process.env.HELLO) // world
  313. ```
  314. For example, customizing the source AND target:
  315. ```js
  316. const dotenv = require('dotenv')
  317. const parsed = { HELLO: 'universe' }
  318. const target = { HELLO: 'world' } // empty object
  319. dotenv.populate(target, parsed, { override: true, debug: true })
  320. console.log(target) // { HELLO: 'universe' }
  321. ```
  322. #### options
  323. ##### Debug
  324. Default: `false`
  325. Turn on logging to help debug why certain keys or values are not being populated as you expect.
  326. ##### override
  327. Default: `false`
  328. Override any environment variables that have already been set.
  329. ## ❓ FAQ
  330. ### Why is the `.env` file not loading my environment variables successfully?
  331. Most 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).
  332. Turn on debug mode and try again..
  333. ```js
  334. require('dotenv').config({ debug: true })
  335. ```
  336. You will receive a helpful error outputted to your console.
  337. ### Should I commit my `.env` file?
  338. No. We **strongly** recommend against committing your `.env` file to version
  339. control. It should only include environment-specific values such as database
  340. passwords or API keys. Your production database should have a different
  341. password than your development database.
  342. ### Should I have multiple `.env` files?
  343. We 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 form `.env` for example). It is better to duplicate values if necessary across each `.env.environment` file.
  344. > 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.
  345. >
  346. > – [The Twelve-Factor App](http://12factor.net/config)
  347. ### What rules does the parsing engine follow?
  348. The parsing engine currently supports the following rules:
  349. - `BASIC=basic` becomes `{BASIC: 'basic'}`
  350. - empty lines are skipped
  351. - lines beginning with `#` are treated as comments
  352. - `#` marks the beginning of a comment (unless when the value is wrapped in quotes)
  353. - empty values become empty strings (`EMPTY=` becomes `{EMPTY: ''}`)
  354. - inner quotes are maintained (think JSON) (`JSON={"foo": "bar"}` becomes `{JSON:"{\"foo\": \"bar\"}"`)
  355. - 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'}`)
  356. - single and double quoted values are escaped (`SINGLE_QUOTE='quoted'` becomes `{SINGLE_QUOTE: "quoted"}`)
  357. - single and double quoted values maintain whitespace from both ends (`FOO=" some value "` becomes `{FOO: ' some value '}`)
  358. - double quoted values expand new lines (`MULTILINE="new\nline"` becomes
  359. ```
  360. {MULTILINE: 'new
  361. line'}
  362. ```
  363. - backticks are supported (`` BACKTICK_KEY=`This has 'single' and "double" quotes inside of it.` ``)
  364. ### What happens to environment variables that were already set?
  365. By 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.
  366. If instead, you want to override `process.env` use the `override` option.
  367. ```javascript
  368. require('dotenv').config({ override: true })
  369. ```
  370. ### How come my environment variables are not showing up for React?
  371. Your 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.
  372. If 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.
  373. If 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.
  374. ### Can I customize/write plugins for dotenv?
  375. Yes! `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:
  376. ```js
  377. const dotenv = require('dotenv')
  378. const variableExpansion = require('dotenv-expand')
  379. const myEnv = dotenv.config()
  380. variableExpansion(myEnv)
  381. ```
  382. ### How do I use dotenv with `import`?
  383. Simply..
  384. ```javascript
  385. // index.mjs (ESM)
  386. import 'dotenv/config' // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
  387. import express from 'express'
  388. ```
  389. A little background..
  390. > When you run a module containing an `import` declaration, the modules it imports are loaded first, then each module body is executed in a depth-first traversal of the dependency graph, avoiding cycles by skipping anything already executed.
  391. >
  392. > – [ES6 In Depth: Modules](https://hacks.mozilla.org/2015/08/es6-in-depth-modules/)
  393. What does this mean in plain language? It means you would think the following would work but it won't.
  394. `errorReporter.mjs`:
  395. ```js
  396. class Client {
  397. constructor (apiKey) {
  398. console.log('apiKey', apiKey)
  399. this.apiKey = apiKey
  400. }
  401. }
  402. export default new Client(process.env.API_KEY)
  403. ```
  404. `index.mjs`:
  405. ```js
  406. // Note: this is INCORRECT and will not work
  407. import * as dotenv from 'dotenv'
  408. dotenv.config()
  409. import errorReporter from './errorReporter.mjs' // process.env.API_KEY will be blank!
  410. ```
  411. `process.env.API_KEY` will be blank.
  412. Instead, `index.mjs` should be written as..
  413. ```js
  414. import 'dotenv/config'
  415. import errorReporter from './errorReporter.mjs'
  416. ```
  417. Does that make sense? It's a bit unintuitive, but it is how importing of ES6 modules work. Here is a [working example of this pitfall](https://github.com/dotenv-org/examples/tree/master/usage/dotenv-es6-import-pitfall).
  418. There are two alternatives to this approach:
  419. 1. Preload with dotenvx: `dotenvx run -- node index.js` (_Note: you do not need to `import` dotenv with this approach_)
  420. 2. Create a separate file that will execute `config` first as outlined in [this comment on #133](https://github.com/motdotla/dotenv/issues/133#issuecomment-255298822)
  421. ### Why am I getting the error `Module not found: Error: Can't resolve 'crypto|os|path'`?
  422. You are using dotenv on the front-end and have not included a polyfill. Webpack < 5 used to include these for you. Do the following:
  423. ```bash
  424. npm install node-polyfill-webpack-plugin
  425. ```
  426. Configure your `webpack.config.js` to something like the following.
  427. ```js
  428. require('dotenv').config()
  429. const path = require('path');
  430. const webpack = require('webpack')
  431. const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
  432. module.exports = {
  433. mode: 'development',
  434. entry: './src/index.ts',
  435. output: {
  436. filename: 'bundle.js',
  437. path: path.resolve(__dirname, 'dist'),
  438. },
  439. plugins: [
  440. new NodePolyfillPlugin(),
  441. new webpack.DefinePlugin({
  442. 'process.env': {
  443. HELLO: JSON.stringify(process.env.HELLO)
  444. }
  445. }),
  446. ]
  447. };
  448. ```
  449. Alternatively, just use [dotenv-webpack](https://github.com/mrsteele/dotenv-webpack) which does this and more behind the scenes for you.
  450. ### What about variable expansion?
  451. Try [dotenv-expand](https://github.com/motdotla/dotenv-expand)
  452. ### What about syncing and securing .env files?
  453. Use [dotenvx](https://github.com/dotenvx/dotenvx) to unlock syncing encrypted .env files over git.
  454. ### What if I accidentally commit my `.env` file to code?
  455. Remove 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.
  456. ```
  457. brew install dotenvx/brew/dotenvx
  458. dotenvx precommit --install
  459. ```
  460. ### How can I prevent committing my `.env` file to a Docker build?
  461. Use the [docker prebuild hook](https://dotenvx.com/docs/features/prebuild).
  462. ```bash
  463. # Dockerfile
  464. ...
  465. RUN curl -fsS https://dotenvx.sh/ | sh
  466. ...
  467. RUN dotenvx prebuild
  468. CMD ["dotenvx", "run", "--", "node", "index.js"]
  469. ```
  470. ## Contributing Guide
  471. See [CONTRIBUTING.md](CONTRIBUTING.md)
  472. ## CHANGELOG
  473. See [CHANGELOG.md](CHANGELOG.md)
  474. ## Who's using dotenv?
  475. [These npm modules depend on it.](https://www.npmjs.com/browse/depended/dotenv)
  476. Projects that expand it often use the [keyword "dotenv" on npm](https://www.npmjs.com/search?q=keywords:dotenv).