@dotenvx/dotenvx 2.30.0 → 2.31.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/CHANGELOG.md +24 -2
  2. package/README.md +81 -749
  3. package/package.json +3 -3
  4. package/src/cli/actions/{validate.js → check.js} +3 -3
  5. package/src/cli/actions/feedback.js +42 -0
  6. package/src/cli/actions/init.js +56 -2
  7. package/src/cli/commands/armor.js +1 -1
  8. package/src/cli/commands/primitives.js +46 -0
  9. package/src/cli/dotenvx.js +33 -16
  10. package/src/lib/api/postFeedback.js +31 -0
  11. package/src/lib/custodians/resolveLocalKey.js +68 -0
  12. package/src/lib/envfile/discovery/discoverEnvFiles.js +29 -0
  13. package/src/lib/envfile/discovery/extractEnvKeys.js +173 -0
  14. package/src/lib/envfile/discovery/scanSource.js +79 -0
  15. package/src/lib/{helpers → envfile/parsing}/readEnvfile.js +3 -3
  16. package/src/lib/envfile/rendering/normalizeEnvfile.js +56 -0
  17. package/src/lib/envfile/rendering/renderEnvfile.js +26 -0
  18. package/src/lib/{helpers → envfile/validation}/validate.js +2 -2
  19. package/src/lib/{helpers → envfile/validation}/validateEnvfile.js +1 -1
  20. package/src/lib/helpers/checklist.js +1 -1
  21. package/src/lib/helpers/errors.js +1 -1
  22. package/src/lib/helpers/prompts.js +17 -0
  23. package/src/lib/main.js +5 -1
  24. package/src/lib/services/armorPush.js +3 -15
  25. package/src/lib/services/armorUp.js +5 -12
  26. package/src/lib/services/init.js +34 -12
  27. package/src/lib/services/validate.js +2 -2
  28. package/src/cli/actions/define.js +0 -17
  29. /package/src/lib/{grammars → envfile/parsing}/envfile.peggy +0 -0
  30. /package/src/lib/{helpers → envfile/parsing}/envfileParser.js +0 -0
  31. /package/src/lib/{helpers → envfile/parsing}/formatEnvfileSyntaxError.js +0 -0
  32. /package/src/lib/{helpers → envfile/validation}/encryptedSources.js +0 -0
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  [![dotenvx](https://dotenvx.com/banner.png?v2)](https://dotenvx.com)
2
2
 
3
- *a secure dotenv*–from the creator of [`dotenv`](https://github.com/motdotla/dotenv).
3
+ *A secure dotenv*–from the creator of [`dotenv`](https://github.com/motdotla/dotenv).
4
4
 
5
- * run anywhere (cross-platform)
6
- * multi-environment
7
- * encrypted envs
5
+ * Encrypt
6
+ * Commit
7
+ * Ship
8
8
 
9
- [Read the whitepaper](https://dotenvx.com/dotenvx.pdf?v=README)
9
+ [Install](https://dotenvx.com/docs/install) · [Quickstart](https://dotenvx.com/docs/quickstart)
10
10
 
11
11
   
12
12
 
@@ -108,6 +108,49 @@ dotenvx encrypt
108
108
 
109
109
   
110
110
 
111
+ ## Usage
112
+
113
+ *Encrypt* your secrets in `.env` files. The values become ciphertext and only your private key can unlock them.
114
+
115
+ ```sh
116
+ $ dotenvx encrypt
117
+ ◈ encrypted (.env)
118
+ ```
119
+
120
+ *Commit* your encrypted `.env` files with your code. It's safe. Now you can securely share secrets through git.
121
+
122
+ ```sh
123
+ $ git add .env
124
+ $ git commit -m "encrypt .env"
125
+ ```
126
+
127
+ *Ship* your code and secrets together. Dotenvx uses your private key to decrypt and inject your secrets just-in-time to your code.
128
+
129
+ ```sh
130
+ $ dotenvx run -- node index.js
131
+ ⟐ injected env (2) from .env
132
+ ```
133
+
134
+  
135
+
136
+ ## Design
137
+
138
+ Three widely used and proven primitives make up Dotenvx's design. Git, .env, and secp256k1.
139
+
140
+ We chose git because it is the best way to deliver digital goods. It is the container ship of the digital world. All code travels on its ships. Why not secrets? Why invent an inferior secrets delivery mechanism when the world class one is right there at your fingertips.
141
+
142
+ We chose .env because it is the open standard for loading secrets into code. It represents environment variables, the core primitive that all secrets end up injected into at runtime of code.
143
+
144
+ Lastly, we needed to choose an encryption algorithm. Encryption of the values inside the .env file would allow us to place those values with code, leveraging git's distribution advantages while still following the twelve-factor config – by separating the decryption key from the code (environment).
145
+
146
+ It was important that we choose a proven, simple, asymmetric standard with small keys. We chose secp256k1, battle-tested by Bitcoin for more than seventeen years. We made cryptography an opinionated choice so developers wouldn't have to. Encryption just worked.
147
+
148
+ The result is a system built entirely from primitives, developers already understand, and infrastructure they already use. Secrets can travel with code without becoming part of the code. Git distributes them, .env defines how apps consume them, and secp256k1 keeps their values unreadable. The kicker, all this works by setting a single private key on your infrastructure - no more risky async coordination of secrets, no more centralized downtime risk. Your secrets are always just there with your code, ready to be unlocked at runtime.
149
+
150
+ [Read the whitepaper →](https://dotenvx.com/dotenvx.pdf?v=README)
151
+
152
+  
153
+
111
154
  ## Run Anywhere
112
155
 
113
156
  ```sh
@@ -122,7 +165,7 @@ Hello World # with dotenvx
122
165
  > :-D
123
166
  ```
124
167
 
125
- see [quickstart guides](https://dotenvx.com/docs/quickstarts)
168
+ see [quickstart guides](https://dotenvx.com/docs)
126
169
 
127
170
  More examples
128
171
 
@@ -524,24 +567,6 @@ $ dotenvx run --quiet -- sh -c 'echo Hello $HELLO'
524
567
  Hello World
525
568
  ```
526
569
 
527
- </details>
528
- <details><summary>Fish 🐠</summary><br>
529
-
530
- ```sh
531
- $ echo "HELLO=World" > .env
532
-
533
- $ dotenvx run --quiet -- sh -c 'echo Hello $HELLO'
534
- Hello World
535
- ```
536
-
537
- </details>
538
- <details><summary>Cron ⏰</summary><br>
539
-
540
- ```sh
541
- # run every day at 8am
542
- 0 8 * * * dotenvx run -- /path/to/myscript.sh
543
- ```
544
-
545
570
  </details>
546
571
  <details><summary>Frameworks ▲</summary><br>
547
572
 
@@ -660,27 +685,6 @@ $ npm run start
660
685
  Hello World
661
686
  ```
662
687
 
663
- </details>
664
- <details><summary>asdf</summary><br>
665
-
666
- ```sh
667
- # use dotenvx with asdf
668
- $ asdf plugin add dotenvx
669
- $ asdf install dotenvx latest
670
- ```
671
-
672
- thank you [@jgburet](https://github.com/jgburet/asdf-dotenvx) of Paris 🇫🇷
673
-
674
- </details>
675
- <details><summary>Git</summary><br>
676
-
677
- ```sh
678
- # use as a git submodule
679
- $ git dotenvx run -- node index.js
680
- $ git dotenvx run -- next dev
681
- $ git dotenvx run -- npm start
682
- ```
683
-
684
688
  </details>
685
689
  <details><summary>Variable Expansion</summary><br>
686
690
 
@@ -872,18 +876,6 @@ $ dotenvx encrypt
872
876
 
873
877
  > A `DOTENV_PUBLIC_KEY` (encryption key) and a `DOTENV_PRIVATE_KEY` (decryption key) are generated using the same public-key cryptography as [Bitcoin](https://en.bitcoin.it/wiki/Secp256k1).
874
878
 
875
- New private keys created by `encrypt` and encrypted `set` default to your OS secret store: macOS Keychain, Windows Credential Manager, or Linux Secret Service. The interactive picker offers Local Custody through your OS secret store, Local Custody through 1Password when available, and Managed Custody through Armor when logged in. When only the OS store is available, it is selected automatically. Existing `.env.keys` files are not automatically migrated.
876
-
877
- Linux requires `secret-tool` (typically the `libsecret-tools` package), a running Secret Service such as GNOME Keyring, and a user D-Bus session. When native tooling or the service is missing, dotenvx reports the fallback to `.env.keys`. Locked, denied, timed-out, or unverified storage operations fail without falling back to a plaintext key file.
878
-
879
- CI uses file storage. To explicitly use file storage elsewhere, run `dotenvx encrypt --no-native --no-armor --no-1password` (or pass all three flags to `set`). For deployment, continue supplying the private key through your platform's secret injection.
880
-
881
- The 1Password option appears when CLI version 2 is installed and an account is configured (or `OP_SERVICE_ACCOUNT_TOKEN` is set). Detection does not sign in or unlock your vault. Selecting it authenticates as needed, uses the default vault selected by the 1Password CLI, and verifies the saved key before writing the encrypted env file. An unavailable, denied, or cancelled 1Password operation fails without falling back to local key storage.
882
-
883
- 1Password custody stores the key in your default vault and saves only its account/item reference in dotenvx's per-user settings. `run`, `get`, and `keypair` then retrieve it automatically, subject to 1Password authorization. `--no-1password` (where supported) or `DOTENVX_NO_1PASSWORD=true` disables that integration. The local reference is needed for automatic lookup on this machine; on another machine, the key is still accessible in the vault but its locator must also be configured for automatic lookup. No plaintext private key is written to `.env.keys` or passed in command arguments. The “Local Custody” label refers to using your own password manager; 1Password vaults may sync off-machine.
884
-
885
- To move an existing key into the OS store, run `dotenvx native up`. It verifies the stored key before removing it from `.env.keys`. Use `dotenvx native push` to keep a file copy, `dotenvx native pull` to export a copy, or `dotenvx native down` to move it back to `.env.keys`. Add `-f .env.production` for a particular env file. Keep a recoverable copy in your team's secret manager or backup before replacing or losing the machine.
886
-
887
879
  More examples
888
880
 
889
881
  <details><summary>`.env`</summary><br>
@@ -951,13 +943,13 @@ Point `-f` at a directory to load the `.env` inside it. From a workspace, this m
951
943
  ```text
952
944
  my-monorepo/
953
945
  .env
954
- .env.keys
955
946
  apps/
956
947
  web/
957
948
  index.js
958
949
  ```
959
950
 
960
951
  ```sh
952
+ $ dotenvx encrypt
961
953
  $ cd apps/web
962
954
 
963
955
  $ dotenvx get HELLO -f ../..
@@ -968,7 +960,7 @@ $ dotenvx run -f ../.. -- node index.js
968
960
  Hello World
969
961
  ```
970
962
 
971
- Encrypted values work without extra configuration when `.env.keys` sits beside the resolved `.env`.
963
+ With the private key in your OS secret store, dotenvx finds it automatically from any workspace on the same machine.
972
964
 
973
965
  The directory also becomes the base when using a convention:
974
966
 
@@ -978,10 +970,10 @@ $ dotenvx run -f ../.. --convention=nextjs -- node index.js
978
970
  Hello development local
979
971
  ```
980
972
 
981
- If a workspace has its own `.env` but shares the root `.env.keys`, point `-fk` at the root directory:
973
+ For a workspace with its own encrypted `.env`, run from that workspace:
982
974
 
983
975
  ```sh
984
- $ dotenvx run -f . -fk ../.. -- node index.js
976
+ $ dotenvx run -- node index.js
985
977
  ```
986
978
 
987
979
  </details>
@@ -1233,7 +1225,7 @@ Use `--no-1password` to leave `op://` values unresolved.
1233
1225
  $ dotenvx run --no-1password -- node index.js
1234
1226
  ```
1235
1227
 
1236
- The same flag is available for `dotenvx get` and `dotenvx validate`.
1228
+ The same flag is available for `dotenvx get` and `dotenvx check`.
1237
1229
 
1238
1230
  </details>
1239
1231
  <details><summary>`run` - Bitwarden</summary><br>
@@ -1265,7 +1257,7 @@ Use `--no-bitwarden` to skip Bitwarden resolution intentionally.
1265
1257
  $ dotenvx run --no-bitwarden -- node index.js
1266
1258
  ```
1267
1259
 
1268
- The same flag is available for `dotenvx get` and `dotenvx validate`.
1260
+ The same flag is available for `dotenvx get` and `dotenvx check`.
1269
1261
 
1270
1262
  </details>
1271
1263
  <details><summary>`run -f <directory>`</summary><br>
@@ -1565,7 +1557,7 @@ Hello production
1565
1557
  Available log levels are `error, warn, info, verbose, debug, silly` ([source](https://docs.npmjs.com/cli/v8/using-npm/logging#setting-log-levels))
1566
1558
 
1567
1559
  </details>
1568
- <details><summary>`run` with an Envfile</summary><br>
1560
+ <details><summary>`run with an Envfile`</summary><br>
1569
1561
 
1570
1562
  When an `Envfile` is present, `run` automatically validates the resolved environment before starting your command. No validation flag is needed.
1571
1563
 
@@ -1583,6 +1575,9 @@ $ dotenvx run -- node index.js
1583
1575
 
1584
1576
  Envfile validation failures stop the command. Other loading errors require `--strict` to stop execution.
1585
1577
 
1578
+ </details>
1579
+ <details><summary>`run with Envfile file rules`</summary><br>
1580
+
1586
1581
  Use exact file blocks to override rules for selected files:
1587
1582
 
1588
1583
  ```ruby
@@ -1597,13 +1592,12 @@ file ".env.production" do
1597
1592
  end
1598
1593
  ```
1599
1594
 
1600
- Both `dotenvx run -f .env.production -- node index.js` and `dotenvx validate -f .env.production` use the production rules. Block declarations inherit top-level options and override only the options they specify. A block's `encrypted` directive applies to all inherited and newly declared variables; a per-variable `encrypted:` option inside that block overrides it.
1595
+ Both `dotenvx run -f .env.production -- node index.js` and `dotenvx check -f .env.production` use the production rules. Block declarations inherit top-level options and override only the options they specify. A block's `encrypted` directive applies to all inherited and newly declared variables; a per-variable `encrypted:` option inside that block overrides it.
1601
1596
 
1602
1597
  Paths in file blocks are relative to the Envfile. They match the selected paths exactly after path normalization (`./.env.production` matches `.env.production`); they are not basename matches or globs. Directory inputs and `DOTENV_FILE` use their resolved file paths.
1603
1598
 
1604
1599
  When no file block matches, top-level rules apply. When one or more blocks match, each matching block's inherited rules must hold for the final resolved environment. Shell values, fallback files, and `--overload` cannot bypass them. A selected missing file still activates its block. Multiple matching blocks cannot cancel each other's restrictions; conflicting proxy domains are rejected. Blocks cannot be nested, and duplicate declarations within one scope or duplicate file blocks are errors.
1605
1600
 
1606
-
1607
1601
  </details>
1608
1602
  <details><summary>`run --strict`</summary><br>
1609
1603
 
@@ -1709,7 +1703,7 @@ Hello development local
1709
1703
  </details>
1710
1704
  <details><summary>`run -fk`</summary><br>
1711
1705
 
1712
- Specify path to `.env.keys`. This is useful with monorepos.
1706
+ Specify a custom private-key file when using file storage.
1713
1707
 
1714
1708
  ```sh
1715
1709
  $ mkdir -p apps/app1
@@ -1853,7 +1847,7 @@ World
1853
1847
  </details>
1854
1848
  <details><summary>`get KEY -fk`</summary><br>
1855
1849
 
1856
- Specify path to `.env.keys`. This is useful with monorepos.
1850
+ Specify a custom private-key file when using file storage.
1857
1851
 
1858
1852
  ```sh
1859
1853
  $ mkdir -p apps/app1
@@ -2137,7 +2131,7 @@ set HELLO with encryption (.env.production)
2137
2131
  </details>
2138
2132
  <details><summary>`set KEY value -fk`</summary><br>
2139
2133
 
2140
- Specify path to `.env.keys`. This is useful with monorepos.
2134
+ Specify a custom private-key file when using file storage.
2141
2135
 
2142
2136
  ```sh
2143
2137
  $ mkdir -p apps/app1
@@ -2333,7 +2327,7 @@ $ dotenvx encrypt -f .env.production --no-create
2333
2327
  </details>
2334
2328
  <details><summary>`encrypt -fk`</summary><br>
2335
2329
 
2336
- Specify path to `.env.keys`. This is useful with monorepos.
2330
+ Specify a custom private-key file when using file storage.
2337
2331
 
2338
2332
  ```sh
2339
2333
  $ mkdir -p apps/app1
@@ -2487,7 +2481,7 @@ $ dotenvx decrypt -f .env.production
2487
2481
  </details>
2488
2482
  <details><summary>`decrypt -fk`</summary><br>
2489
2483
 
2490
- Specify path to `.env.keys`. This is useful with monorepos.
2484
+ Specify a custom private-key file when using file storage.
2491
2485
 
2492
2486
  ```sh
2493
2487
  $ mkdir -p apps/app1
@@ -2633,7 +2627,7 @@ $ dotenvx keypair -f .env.production
2633
2627
  </details>
2634
2628
  <details><summary>`keypair -fk`</summary><br>
2635
2629
 
2636
- Specify path to `.env.keys`. This is useful for printing public/private keys for monorepos.
2630
+ Print keys from a custom private-key file when using file storage.
2637
2631
 
2638
2632
  ```sh
2639
2633
  $ mkdir -p apps/app1
@@ -2704,649 +2698,11 @@ $ dotenvx keypair --pretty-print
2704
2698
  ```
2705
2699
 
2706
2700
  </details>
2707
- <details><summary>`ls`</summary><br>
2708
-
2709
- Print all `.env` files in a tree structure.
2710
-
2711
- ```sh
2712
- $ touch .env
2713
- $ touch .env.production
2714
- $ mkdir -p apps/backend
2715
- $ touch apps/backend/.env
2716
-
2717
- $ dotenvx ls
2718
- ├─ .env.production
2719
- ├─ .env
2720
- └─ apps
2721
- └─ backend
2722
- └─ .env
2723
- ```
2724
-
2725
- </details>
2726
- <details><summary>`ls directory`</summary><br>
2727
-
2728
- Print all `.env` files inside a specified path to a directory.
2729
-
2730
- ```sh
2731
- $ touch .env
2732
- $ touch .env.production
2733
- $ mkdir -p apps/backend
2734
- $ touch apps/backend/.env
2735
-
2736
- $ dotenvx ls apps/backend
2737
- └─ .env
2738
- ```
2739
-
2740
- </details>
2741
- <details><summary>`ls -f`</summary><br>
2742
-
2743
- Glob `.env` filenames matching a wildcard.
2744
-
2745
- ```sh
2746
- $ touch .env
2747
- $ touch .env.production
2748
- $ mkdir -p apps/backend
2749
- $ touch apps/backend/.env
2750
- $ touch apps/backend/.env.prod
2751
-
2752
- $ dotenvx ls -f **/.env.prod*
2753
- ├─ .env.production
2754
- └─ apps
2755
- └─ backend
2756
- └─ .env.prod
2757
- ```
2758
-
2759
- </details>
2760
- <details><summary>`ls -ef`</summary><br>
2761
-
2762
- Glob `.env` filenames excluding a wildcard.
2763
-
2764
- ```sh
2765
- $ touch .env
2766
- $ touch .env.production
2767
- $ mkdir -p apps/backend
2768
- $ touch apps/backend/.env
2769
- $ touch apps/backend/.env.prod
2770
-
2771
- $ dotenvx ls -ef '**/.env.prod*'
2772
- ├─ .env
2773
- └─ apps
2774
- └─ backend
2775
- └─ .env
2776
- ```
2777
-
2778
- </details>
2779
- <details><summary>`ls --json`</summary><br>
2780
-
2781
- Print all matching `.env` files as a JSON array of absolute filepaths. Progress and summary details are written to stderr, so stdout can be safely piped to another command or file.
2782
-
2783
- ```sh
2784
- $ dotenvx ls --json
2785
- [
2786
- "/path/to/project/.env",
2787
- "/path/to/project/apps/backend/.env"
2788
- ]
2789
-
2790
- $ dotenvx ls --json > dotenv-files.json
2791
- ```
2792
-
2793
- </details>
2794
- <details><summary>`define` (hidden)</summary><br>
2701
+ <details><summary>`hidden`</summary><br>
2795
2702
 
2796
- Create an `Envfile` to validate your project's environment variables:
2703
+ Dotenvx has a slew of hidden commands.
2797
2704
 
2798
- ```sh
2799
- $ dotenvx define
2800
- ≡ defined (Envfile)
2801
- ```
2802
-
2803
- Merges variable names from both `.env.example` and `.env`, skipping missing files and including each name once. Use `dotenvx define -f .env.production` to read only a specific input. If neither default file exists, it creates a starter. An existing `Envfile` is always left unchanged. The hidden `dotenvx init` command currently performs the same step.
2804
-
2805
- The first line is `encrypted false` by default, or `encrypted true` if any application variable assignment in either input starts with `encrypted:`. Duplicate assignments are all inspected. This sets the encryption requirement for all declarations; use `encrypted: false` on individual variables that should remain plaintext.
2806
-
2807
- Generated declarations are required by default. Review them and mark optional variables with `optional: true`.
2808
-
2809
- Only names are copied: values are never included, decrypted, expanded, or fetched from secret providers. Dotenvx public and private key entries are excluded. Your env files are unchanged.
2810
-
2811
- Run `dotenvx validate` (or `dotenvx validate -f .env.production` for another file) to check your configuration. Once `Envfile` exists, `dotenvx run` validates automatically before starting your command.
2812
-
2813
- </details>
2814
- <details><summary>`validate`</summary><br>
2815
-
2816
- Validate resolved `.env` values against an `Envfile` without running a command. An `Envfile` in the current directory is required; `.env.example` is not used for validation.
2817
-
2818
- ```ruby
2819
- # Envfile
2820
- env "DATABASE_URL", type: "url"
2821
- env "PORT", type: "port"
2822
- env "SENTRY_DSN", optional: true
2823
- ```
2824
-
2825
- ```sh
2826
- $ dotenvx validate
2827
- [INVALID_ENV] DATABASE_URL is required; PORT is required
2828
-
2829
- $ dotenvx validate -f .env.production -fk .env.keys
2830
- ```
2831
-
2832
- The command enforces required values, types, enums, bounds, and encryption requirements. It exits with code `1` on validation or other loading errors. Missing env files are reported but do not fail validation when the resolved values satisfy Envfile; use `--strict` to make missing files fatal too. On success, it prints `▣ valid (.env)` (listing the loaded input files) and exits with code `0` on success. It does not change your shell's environment.
2833
-
2834
- A missing Envfile reports `ENVFILE_REQUIRED`; invalid syntax reports `MALFORMED_ENVFILE`.
2835
-
2836
- </details>
2837
- <details><summary>`validate --ignore`</summary><br>
2838
-
2839
- Ignore specific loading or value-validation errors:
2840
-
2841
- ```sh
2842
- $ dotenvx validate --ignore=MISSING_ENV_FILE
2843
- $ dotenvx validate --ignore=MISSING_ENV_FILE INVALID_ENV
2844
- $ DOTENV_IGNORE=MISSING_ENV_FILE dotenvx validate
2845
- ```
2846
-
2847
- An Envfile is still required, even when errors are ignored.
2848
-
2849
- </details>
2850
- <details><summary>`genexample`</summary><br>
2851
-
2852
- In one command, generate a `.env.example` file from your current `.env` file contents.
2853
-
2854
- ```sh
2855
- $ echo "HELLO=World" > .env
2856
-
2857
- $ dotenvx genexample
2858
- ▣ generated (.env.example)
2859
- ```
2860
-
2861
- ```ini
2862
- # .env.example
2863
- HELLO=""
2864
- ```
2865
-
2866
- </details>
2867
- <details><summary>`genexample -f`</summary><br>
2868
-
2869
- Pass multiple `.env` files to generate your `.env.example` file from the combination of their contents.
2870
-
2871
- ```sh
2872
- $ echo "HELLO=World" > .env
2873
- $ echo "DB_HOST=example.com" > .env.production
2874
-
2875
- $ dotenvx genexample -f .env,.env.production
2876
- ▣ generated (.env.example)
2877
- ```
2878
-
2879
- ```ini
2880
- # .env.example
2881
- HELLO=""
2882
- DB_HOST=""
2883
- ```
2884
-
2885
- </details>
2886
- <details><summary>`genexample directory`</summary><br>
2887
-
2888
- Generate a `.env.example` file inside the specified directory. Useful for monorepos.
2889
-
2890
- ```sh
2891
- $ echo "HELLO=World" > .env
2892
- $ mkdir -p apps/backend
2893
- $ echo "HELLO=Backend" > apps/backend/.env
2894
-
2895
- $ dotenvx genexample apps/backend
2896
- ▣ generated (.env.example)
2897
- ```
2898
-
2899
- ```ini
2900
- # apps/backend/.env.example
2901
- HELLO=""
2902
- ```
2903
-
2904
- </details>
2905
- <details><summary>`gitignore`</summary><br>
2906
-
2907
- Gitignore your `.env` files.
2908
-
2909
- ```sh
2910
- $ dotenvx gitignore
2911
- ▣ ignored .env* (.gitignore)
2912
- ```
2913
-
2914
- </details>
2915
- <details><summary>`gitignore --pattern`</summary><br>
2916
-
2917
- Gitignore specific pattern(s) of `.env` files.
2918
-
2919
- ```sh
2920
- $ dotenvx gitignore --pattern .env.keys
2921
- ▣ ignored .env.keys (.gitignore)
2922
- ```
2923
-
2924
- </details>
2925
- <details><summary>`precommit`</summary><br>
2926
-
2927
- Deprecated in favor of `dotenvx protect`. Existing hooks continue checking files and print a migration notice on each invocation. Run `dotenvx protect` inside the repository to install global staging protection and remove its recognized dotenvx hook block. Other hook commands are preserved; customized or shared hooks may require manual cleanup.
2928
-
2929
- Prevent `.env` files from being committed to code.
2930
-
2931
- ```sh
2932
- $ dotenvx precommit
2933
- ▣ .env files (1) protected (encrypted or gitignored)
2934
- ```
2935
-
2936
- </details>
2937
- <details><summary>`precommit --install`</summary><br>
2938
-
2939
- Install a pre-commit hook in the current repository:
2940
-
2941
- ```sh
2942
- $ dotenvx precommit --install
2943
- ▣ dotenvx precommit installed [.git/hooks/pre-commit]
2944
- ```
2945
-
2946
- For protection during staging, use `dotenvx protect`.
2947
-
2948
- </details>
2949
- <details><summary>`precommit --uninstall`</summary><br>
2950
-
2951
- Remove the installed dotenvx pre-commit hook without installing replacement protection:
2952
-
2953
- ```sh
2954
- $ dotenvx precommit --uninstall
2955
- ```
2956
-
2957
- This removes recognized dotenvx installer blocks while preserving other hook commands. It also supports `dotenvx ext precommit --uninstall`. Unrecognized, symlinked, or external shared hooks are left unchanged with a manual-cleanup message.
2958
-
2959
- </details>
2960
- <details><summary>`protect` (hidden)</summary><br>
2961
-
2962
- For a Docker build-time check instead of Git setup, use `RUN dotenvx protect --docker` in your Dockerfile, or `RUN dotenvx protect --docker apps/backend` for a specific directory. This replaces `prebuild` with the same checks, without prompts or Git configuration changes. It does not edit Dockerfiles or prevent files from reaching the builder; use `.dockerignore` for that.
2963
-
2964
- Install a required Git clean filter for all existing and future repositories for your user. Run this once, even outside a Git repository:
2965
-
2966
- ```sh
2967
- $ dotenvx protect
2968
- ```
2969
-
2970
- Interactive setup shows one checklist with both protections selected every time, even if you previously turned them off:
2971
-
2972
- ```text
2973
- Set protections
2974
- ● Protect plaintext secrets from code commits (.env*)
2975
- ● Protect private keys from code commits (.env.keys*)
2976
-
2977
- Install protections
2978
- ```
2979
-
2980
- Use arrow keys to move and Enter or Space to toggle a choice. The action row changes to **Install protections**, **Apply changes**, **Remove protections**, or **Done**. Press Enter on that row to apply. Unchecking removes that protection; clearing both reports `⛉ unprotected (none)`. Cancelling leaves settings unchanged.
2981
-
2982
- The first installs the staging filter. The second adds `.env.keys*` to your global Git ignore file, preserving existing rules and any configured `core.excludesFile`. Otherwise, it uses `$XDG_CONFIG_HOME/git/ignore` or `~/.config/git/ignore`. This skips private-key files during normal adds; the filter still rejects forced adds when enabled. Only dotenvx-owned ignore rules are removed. Older or manually added `.env.keys*` rules without an ownership record require manual removal. Noninteractive and CI runs retain filter-only installation without prompting or removing existing protections.
2983
-
2984
- When run inside a repository with the filter selected, this also removes recognized dotenvx pre-commit hook blocks and legacy repo-local `precommit --clean` filter registrations after global protection is successfully installed. Custom filter commands are preserved. Run it in each repository with an old hook or filter override to migrate that repository.
2985
-
2986
- The filter rejects plaintext `.env*`, `*.env`, `.flaskenv`, `.dev.vars*`, and files directly inside `.env.d/` directories at any depth before staging, including with `git add -A` or `git add -f`. Encrypted files pass through unchanged. `.env.example`, `.env.vault`, and `.env.x` retain their exemptions; `.env.keys*` files are always rejected.
2987
-
2988
- This writes the filter configuration to your global Git config and adds the env-file rules to your global attributes file. Re-run `dotenvx protect` with the filter selected to refresh it after upgrading or moving the executable. It preserves an existing `core.attributesFile`; otherwise it uses `$XDG_CONFIG_HOME/git/attributes` or `~/.config/git/attributes`. It does not inspect content already staged before installation. Repository attributes and configuration can override the global protection. Use a persistent dotenvx installation.
2989
-
2990
- </details>
2991
- <details><summary>`precommit directory`</summary><br>
2992
-
2993
- Prevent `.env` files from being committed to code inside a specified path to a directory.
2994
-
2995
- ```sh
2996
- $ echo "HELLO=World" > .env
2997
- $ mkdir -p apps/backend
2998
- $ echo "HELLO=Backend" > apps/backend/.env
2999
-
3000
- $ dotenvx precommit apps/backend
3001
- ▣ apps/backend/.env not protected (encrypted or gitignored)
3002
- ```
3003
-
3004
- </details>
3005
- <details><summary>`prebuild`</summary><br>
3006
-
3007
- Deprecated. Use `dotenvx protect --docker` for the same build-time check.
3008
-
3009
- Add it to your `Dockerfile`.
3010
-
3011
- ```Containerfile
3012
- # Install via script
3013
- RUN curl -fsS https://dotenvx.sh | sh
3014
-
3015
- # Or copy binary from official image
3016
- COPY --from=dotenv/dotenvx:latest /usr/local/bin/dotenvx /bin/local/bin
3017
-
3018
- # ... orther container commands
3019
-
3020
- RUN dotenvx protect --docker
3021
- CMD ["/usr/local/bin/dotenvx", "run", "--", "node", "index.js"]
3022
- ```
3023
-
3024
- </details>
3025
- <details><summary>`prebuild directory`</summary><br>
3026
-
3027
- Deprecated. Use `dotenvx protect --docker <directory>` for the same build-time check in a specified directory.
3028
-
3029
- Add it to your `Dockerfile`.
3030
-
3031
- ```Containerfile
3032
- # Install via script
3033
- RUN curl -fsS https://dotenvx.sh | sh
3034
-
3035
- # Or copy binary from official image
3036
- COPY --from=dotenv/dotenvx:latest /usr/local/bin/dotenvx /bin/local/bin
3037
-
3038
- # ... orther container commands
3039
-
3040
- RUN dotenvx protect --docker apps/backend
3041
- CMD ["/usr/local/bin/dotenvx", "run", "--", "node", "apps/backend/index.js"]
3042
- ```
3043
-
3044
- </details>
3045
- <details><summary>`lock`</summary><br>
3046
-
3047
- Lock private keys with a local passphrase to keep them protected inside `.env.keys`.
3048
-
3049
- ```
3050
- # example
3051
- DOTENV_PRIVATE_KEY=locked:02f5b97ad58b49ae324cd4e7937bc19b251d006b31cacf46f789eeaf03f923cedc:AZIPDxKqjPLiGl5b4CqVGbR3CIBDUcqHthGaoeWLoUvxbTHJkj3jGoGWGaxFSDUJGQUmWDaExRzxKpVydYF_7qiWr1ecqksOFho5t3EMwKbqX2-y-LZO9K3a4SJaYAjDJXpn3NwG4vAt1oLmGA
3052
- ```
3053
-
3054
- </details>
3055
- <details><summary>`lock up`</summary><br>
3056
-
3057
- Lock a private key in `.env.keys` with a local passphrase.
3058
-
3059
- ```sh
3060
- $ dotenvx lock up
3061
- ```
3062
-
3063
- Here's what a locked key looks like:
3064
-
3065
- ```ini
3066
- # .env.keys
3067
- DOTENV_PRIVATE_KEY=locked:02f5b97ad58b49ae324cd4e7937bc19b251d006b31cacf46f789eeaf03f923cedc:AZIPDxKqjPLiGl5b4CqVGbR3CIBDUcqHthGaoeWLoUvxbTHJkj3jGoGWGaxFSDUJGQUmWDaExRzxKpVydYF_7qiWr1ecqksOFho5t3EMwKbqX2-y-LZO9K3a4SJaYAjDJXpn3NwG4vAt1oLmGA
3068
- ```
3069
-
3070
- Specify files with `-f` and `-fk`.
3071
-
3072
- ```sh
3073
- $ dotenvx lock up -f .env.production -fk .env.keys
3074
- ```
3075
-
3076
- </details>
3077
- <details><summary>`lock down`</summary><br>
3078
-
3079
- Unlock a private key in `.env.keys` with its local passphrase.
3080
-
3081
- ```sh
3082
- $ dotenvx lock down
3083
- ```
3084
-
3085
- </details>
3086
- <details><summary>`native`</summary><br>
3087
-
3088
- Move private keys into your OS secret store.
3089
-
3090
- Native commands support macOS Keychain, Linux Secret Service, and Windows Credential Manager.
3091
-
3092
- On Linux, `secret-tool` and an available Secret Service are required.
3093
-
3094
- </details>
3095
- <details><summary>`native up`</summary><br>
3096
-
3097
- Move a private key from `.env.keys` into your OS secret store.
3098
-
3099
- ```sh
3100
- $ dotenvx native up
3101
- ```
3102
-
3103
- Specify files with `-f` and `-fk`.
3104
-
3105
- ```sh
3106
- $ dotenvx native up -f .env.production -fk .env.keys
3107
- ```
3108
-
3109
- </details>
3110
- <details><summary>`native down`</summary><br>
3111
-
3112
- Move a private key from your OS secret store back into `.env.keys`.
3113
-
3114
- ```sh
3115
- $ dotenvx native down
3116
- ```
3117
-
3118
- </details>
3119
- <details><summary>`native push`</summary><br>
3120
-
3121
- Copy a private key from `.env.keys` into your OS secret store.
3122
-
3123
- ```sh
3124
- $ dotenvx native push
3125
- ```
3126
-
3127
- </details>
3128
- <details><summary>`native pull`</summary><br>
3129
-
3130
- Copy a private key from your OS secret store into `.env.keys`.
3131
-
3132
- ```sh
3133
- $ dotenvx native pull
3134
- ```
3135
-
3136
- </details>
3137
- <details><summary>`armor`</summary><br>
3138
-
3139
- Move private keys into [Dotenvx Armor ⛨](https://dotenvx.com/armor) for off-device storage, sharing with your team, and audited access.
3140
-
3141
- </details>
3142
- <details><summary>`armor up`</summary><br>
3143
-
3144
- Move a private key from `.env.keys` into Dotenvx Armor.
3145
-
3146
- ```sh
3147
- $ dotenvx armor login
3148
- $ dotenvx armor up
3149
- ```
3150
-
3151
- Specify environment and team.
3152
-
3153
- ```sh
3154
- $ dotenvx armor up -f .env.production --team acme
3155
- ```
3156
-
3157
- </details>
3158
- <details><summary>`armor down`</summary><br>
3159
-
3160
- Move a private key from Dotenvx Armor back into `.env.keys`.
3161
-
3162
- ```sh
3163
- $ dotenvx armor down
3164
- ```
3165
-
3166
- </details>
3167
- <details><summary>`armor push`</summary><br>
3168
-
3169
- Copy a private key from `.env.keys` into Dotenvx Armor.
3170
-
3171
- ```sh
3172
- $ dotenvx armor push
3173
- ```
3174
-
3175
- </details>
3176
- <details><summary>`armor pull`</summary><br>
3177
-
3178
- Copy a private key from Dotenvx Armor into `.env.keys`.
3179
-
3180
- ```sh
3181
- $ dotenvx armor pull
3182
- ```
3183
-
3184
- Use a token when running non-interactively.
3185
-
3186
- ```sh
3187
- $ dotenvx armor pull -f .env.production --token "$DOTENVX_ARMOR_TOKEN"
3188
- ```
3189
-
3190
- </details>
3191
- <details><summary>`armor open`</summary><br>
3192
-
3193
- Open an armored key in your browser.
3194
-
3195
- ```sh
3196
- $ dotenvx armor open
3197
- ```
3198
-
3199
- Open the armored key for a specific env file.
3200
-
3201
- ```sh
3202
- $ dotenvx armor open -f .env.production
3203
- ```
3204
-
3205
- </details>
3206
- <details><summary>`armor move`</summary><br>
3207
-
3208
- Move an armored key to another team.
3209
-
3210
- ```sh
3211
- $ dotenvx armor move --team acme
3212
- ```
3213
-
3214
- </details>
3215
- <details><summary>`armor login`</summary><br>
3216
-
3217
- Log in to Dotenvx Armor.
3218
-
3219
- ```sh
3220
- $ dotenvx armor login
3221
- ```
3222
-
3223
- After authentication, dotenvx first attempts to store your access token in your operating system's native secret store: macOS Keychain, Windows Credential Manager, or Linux Secret Service. If native secure storage is unavailable, dotenvx falls back to its settings file. This follows a common CLI credential-storage pattern: prefer protected OS storage when available while remaining usable in headless or minimal environments.
3224
-
3225
- </details>
3226
- <details><summary>`armor logout`</summary><br>
3227
-
3228
- Log out of Dotenvx Armor.
3229
-
3230
- ```sh
3231
- $ dotenvx armor logout
3232
- ```
3233
-
3234
- </details>
3235
- <details><summary>`armor status`</summary><br>
3236
-
3237
- Print the current Armor status. It returns `on` when you are logged in and Armor is enabled; otherwise it returns `off`.
3238
-
3239
- ```sh
3240
- $ dotenvx armor status
3241
- on
3242
- ```
3243
-
3244
- </details>
3245
- <details><summary>`armor settings`</summary><br>
3246
-
3247
- Inspect and manage your local Armor settings.
3248
-
3249
- ```sh
3250
- $ dotenvx armor settings username
3251
- $ dotenvx armor settings token
3252
- $ dotenvx armor settings device
3253
- $ dotenvx armor settings hostname
3254
- $ dotenvx armor settings path
3255
- $ dotenvx armor settings on
3256
- $ dotenvx armor settings off
3257
- ```
3258
-
3259
- Access tokens and device public keys are masked by default. Reveal the complete value only when you explicitly need it.
3260
-
3261
- ```sh
3262
- $ dotenvx armor settings token --unmask
3263
- $ dotenvx armor settings device --unmask
3264
- ```
3265
-
3266
- </details>
3267
- <details><summary>`help`</summary><br>
3268
-
3269
- Output help for `dotenvx`.
3270
-
3271
- ```sh
3272
- $ dotenvx help
3273
- Usage: dotenvx run -- yourcommand
3274
-
3275
- a secure dotenv–from the creator of `dotenv`
3276
-
3277
- Options:
3278
- -l, --log-level <level> set log level (default: "info")
3279
- -q, --quiet sets log level to error
3280
- -v, --verbose sets log level to verbose
3281
- -d, --debug sets log level to debug
3282
- -V, --version output the version number
3283
- -h, --help display help for command
3284
-
3285
- Commands:
3286
- run inject env at runtime [dotenvx run -- yourcommand]
3287
- get [KEY] return a single environment variable
3288
- set <KEY> <value> set a single environment variable
3289
- encrypt encrypt .env file(s)
3290
- decrypt decrypt .env file(s)
3291
- keypair [KEY] print public/private keys for .env file(s)
3292
- ls [directory] print all .env files in a tree structure
3293
- gitignore append to .gitignore
3294
- genexample [directory]
3295
- generate .env.example
3296
- validate validate .env file(s) against .env.example
3297
- precommit [directory]
3298
- prevent committing .env files to code
3299
- prebuild [directory]
3300
- prevent including .env files in docker
3301
-
3302
- Professional Security:
3303
- lock ⊡ lock private keys with a local passphrase
3304
- native ⌥ move private keys into your OS secret store
3305
- armor ⛨ move private keys into Dotenvx Armor [www.dotenvx.com/armor]
3306
- ```
3307
-
3308
- You can get more detailed help per command with `dotenvx help COMMAND`.
3309
-
3310
- ```sh
3311
- $ dotenvx help run
3312
- Usage: @dotenvx/dotenvx run [options]
3313
-
3314
- inject env at runtime [dotenvx run -- yourcommand]
3315
-
3316
- Options:
3317
- -e, --env <strings...> environment variable(s) set as string (example: "HELLO=World") (default: [])
3318
- -f, --file <paths...> path(s) to your env file(s) (default: [])
3319
- -fv, --env-vault-file <paths...> path(s) to your .env.vault file(s) (default: [])
3320
- -o, --overload override existing env variables
3321
- --convention <name> load a .env convention (available conventions: ['nextjs'])
3322
- -h, --help display help for command
3323
-
3324
- Examples:
3325
-
3326
- $ dotenvx run -- npm run dev
3327
- $ dotenvx run -- flask --app index run
3328
- $ dotenvx run -- php artisan serve
3329
- $ dotenvx run -- bin/rails s
3330
-
3331
- Try it:
3332
-
3333
- $ echo "HELLO=World" > .env
3334
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
3335
-
3336
- $ dotenvx run -- node index.js
3337
- [dotenvx@1.X.X] injecting env (1) from .env
3338
- Hello World
3339
- ```
3340
-
3341
- </details>
3342
- <details><summary>`--version`</summary><br>
3343
-
3344
- Check current version of `dotenvx`.
3345
-
3346
- ```sh
3347
- $ dotenvx --version
3348
- X.X.X
3349
- ```
2705
+ [See their documentation →](https://dotenvx.com/docs/cli/hidden/)
3350
2706
 
3351
2707
  </details>
3352
2708
 
@@ -3562,7 +2918,7 @@ Hello World
3562
2918
  </details>
3563
2919
  <details><summary>`config(envKeysFile:)` - envKeysFile</summary><br>
3564
2920
 
3565
- Use `envKeysFile` to customize the path to your `.env.keys` file. This is useful with monorepos.
2921
+ Use `envKeysFile` to specify a custom private-key file when using file storage.
3566
2922
 
3567
2923
  ```ini
3568
2924
  # .env
@@ -3879,47 +3235,19 @@ WRONG_PRIVATE_KEY= # the supplied private key cannot decrypt the value
3879
3235
 
3880
3236
  &nbsp;
3881
3237
 
3882
- ## Armor ⛨
3238
+ ## Membership
3883
3239
 
3884
- [![dotenvx-armor](https://dotenvx.com/dotenvx-armor-banner.png?v2)](https://dotenvx.com/armor)
3240
+ [![dotenvx](https://dotenvx.com/membership.png?v2)](https://dotenvx.com/membership)
3885
3241
 
3886
- ```
3887
- ⛨ ARMORED KEYS: Harden your private keys.
3888
- ⮕ install [curl -sfS https://dotenvx.sh/armor | sh]
3889
- ⮕ then run [dotenvx armor login]
3890
- ```
3242
+ <p align="center">Dotenvx Membership. Be part of the .env story.</p>
3891
3243
 
3892
- [Learn more](https://dotenvx.com/armor)
3893
-
3894
- &nbsp;
3895
-
3896
- ## Quickstarts
3897
-
3898
- > Encrypt and run secrets in your language, framework, or tool.
3899
- >
3900
-
3901
- * [Claude](https://dotenvx.com/docs/claude)
3902
- * [Codex](https://dotenvx.com/docs/codex)
3903
- * [1Password](https://dotenvx.com/docs/1password)
3904
- * [Bitwarden](https://dotenvx.com/docs/bitwarden)
3905
- * [Node.js](https://dotenvx.com/docs/nodejs)
3906
- * [Next.js](https://dotenvx.com/docs/nextjs)
3907
- * [Express](https://dotenvx.com/docs/express)
3908
- * [Astro](https://dotenvx.com/docs/astro)
3909
- * [Expo](https://dotenvx.com/docs/expo)
3910
- * [Python](https://dotenvx.com/docs/python)
3911
- * [Ruby](https://dotenvx.com/docs/ruby)
3912
- * [Go](https://dotenvx.com/docs/go)
3913
- * [PHP](https://dotenvx.com/docs/php)
3914
- * [Rust](https://dotenvx.com/docs/rust)
3915
-
3916
- [Browse all quickstarts](https://dotenvx.com/docs/quickstarts)
3244
+ <p align="center"><a href="https://dotenvx.com/membership">Membership Benefits →</a></p>
3917
3245
 
3918
3246
  &nbsp;
3919
3247
 
3920
3248
  ## FAQ
3921
3249
 
3922
- #### How does encryption work?
3250
+ <details><summary>How does encryption work?</summary><br>
3923
3251
 
3924
3252
  Dotenvx uses Elliptic Curve Integrated Encryption Scheme (ECIES) to encrypt each secret with a unique ephemeral key, while ensuring it can be decrypted using a long-term private key.
3925
3253
 
@@ -3927,7 +3255,8 @@ When you initialize encryption, a DOTENV_PUBLIC_KEY (encryption key) and DOTENV_
3927
3255
 
3928
3256
  Your encrypted .env file is then safely committed to code. Even if the file is exposed, secrets remain protected since decryption requires the separate DOTENV_PRIVATE_KEY, which is never stored alongside it. Read [the whitepaper](https://dotenvx.com/dotenvx.pdf?v=README) for more details.
3929
3257
 
3930
- #### Is it safe to commit an encrypted .env file to code?
3258
+ </details>
3259
+ <details><summary>Is it safe to commit an encrypted .env file to code?</summary><br>
3931
3260
 
3932
3261
  Yes. Dotenvx encrypts secrets using AES-256 with ephemeral keys, ensuring that even if the encrypted .env file is exposed, its contents remain secure. The encryption keys themselves are protected using Secp256k1 elliptic curve cryptography, which is widely used for secure key exchange in technologies like Bitcoin.
3933
3262
 
@@ -3935,7 +3264,8 @@ This means that every secret in the .env file is encrypted with a unique AES-256
3935
3264
 
3936
3265
  Breaking this encryption would require brute-forcing both AES-256 and elliptic curve cryptography, which is computationally infeasible with current technology. Read [the whitepaper](https://dotenvx.com/dotenvx.pdf?v=README) for more details.
3937
3266
 
3938
- #### Why am I getting the error `node: .env: not found`?
3267
+ </details>
3268
+ <details><summary>Why am I getting the error <code>node: .env: not found</code>?</summary><br>
3939
3269
 
3940
3270
  You are using Node 20 or greater and it adds a differing implementation of `--env-file` flag support. Rather than warn on a missing `.env` file (like dotenv has historically done), it raises an error: `node: .env: not found`.
3941
3271
 
@@ -3950,6 +3280,8 @@ This fix is easy. Replace `--env-file` with `--file` (or `-f`).
3950
3280
 
3951
3281
  [more context](https://github.com/dotenvx/dotenvx/issues/131)
3952
3282
 
3283
+ </details>
3284
+
3953
3285
  &nbsp;
3954
3286
 
3955
3287
  ## Contributing