@dotenvx/dotenvx 0.38.0 → 0.40.0
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.
- package/README.md +653 -17
- package/package.json +1 -1
- package/src/cli/actions/encryptme.js +73 -0
- package/src/cli/actions/get.js +11 -1
- package/src/cli/actions/run.js +5 -4
- package/src/cli/actions/set.js +43 -9
- package/src/cli/actions/vault/encrypt.js +0 -1
- package/src/cli/commands/hub.js +8 -8
- package/src/cli/dotenvx.js +19 -11
- package/src/lib/helpers/findOrCreatePublicKey.js +4 -2
- package/src/lib/helpers/isEncrypted.js +8 -0
- package/src/lib/helpers/isFullyEncrypted.js +18 -0
- package/src/lib/helpers/isIgnoringDotenvKeys.js +19 -0
- package/src/lib/main.js +14 -3
- package/src/lib/services/encrypt.js +73 -87
- package/src/lib/services/precommit.js +19 -8
- package/src/lib/services/sets.js +32 -10
- package/src/lib/services/vaultEncrypt.js +118 -0
package/README.md
CHANGED
|
@@ -492,7 +492,7 @@ More examples
|
|
|
492
492
|
</details>
|
|
493
493
|
* <details><summary>`--convention` flag</summary><br>
|
|
494
494
|
|
|
495
|
-
|
|
495
|
+
Load envs using [Next.js' convention](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order). Set `--convention` to `nextjs`:
|
|
496
496
|
|
|
497
497
|
```sh
|
|
498
498
|
$ echo "HELLO=development local" > .env.development.local
|
|
@@ -504,8 +504,6 @@ More examples
|
|
|
504
504
|
Hello development local
|
|
505
505
|
```
|
|
506
506
|
|
|
507
|
-
See [next.js environment variable load order](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order)
|
|
508
|
-
|
|
509
507
|
(more conventions available upon request)
|
|
510
508
|
|
|
511
509
|
</details>
|
|
@@ -523,7 +521,7 @@ set HELLO with encryption (.env)
|
|
|
523
521
|
|
|
524
522
|

|
|
525
523
|
|
|
526
|
-
> A `DOTENV_PUBLIC_KEY` (encryption key) and a `DOTENV_PRIVATE_KEY` (decryption key)
|
|
524
|
+
> 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).
|
|
527
525
|
|
|
528
526
|
More examples
|
|
529
527
|
|
|
@@ -586,23 +584,661 @@ More examples
|
|
|
586
584
|
|
|
587
585
|
|
|
588
586
|
|
|
589
|
-
##
|
|
587
|
+
## Advanced usage
|
|
588
|
+
|
|
589
|
+
* <details><summary>`run` - Variable Expansion</summary><br>
|
|
590
|
+
|
|
591
|
+
Reference and expand variables already on your machine for use in your .env file.
|
|
592
|
+
|
|
593
|
+
```ini
|
|
594
|
+
# .env
|
|
595
|
+
USERNAME="username"
|
|
596
|
+
DATABASE_URL="postgres://${USERNAME}@localhost/my_database"
|
|
597
|
+
```
|
|
598
|
+
```js
|
|
599
|
+
// index.js
|
|
600
|
+
console.log('DATABASE_URL', process.env.DATABASE_URL)
|
|
601
|
+
```
|
|
602
|
+
```sh
|
|
603
|
+
$ dotenvx run --debug -- node index.js
|
|
604
|
+
[dotenvx] injecting env (2) from .env
|
|
605
|
+
DATABASE_URL postgres://username@localhost/my_database
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
</details>
|
|
609
|
+
* <details><summary>`run` - Command Substitution</summary><br>
|
|
610
|
+
|
|
611
|
+
Add the output of a command to one of your variables in your .env file.
|
|
612
|
+
|
|
613
|
+
```ini
|
|
614
|
+
# .env
|
|
615
|
+
DATABASE_URL="postgres://$(whoami)@localhost/my_database"
|
|
616
|
+
```
|
|
617
|
+
```js
|
|
618
|
+
// index.js
|
|
619
|
+
console.log('DATABASE_URL', process.env.DATABASE_URL)
|
|
620
|
+
```
|
|
621
|
+
```sh
|
|
622
|
+
$ dotenvx run --debug -- node index.js
|
|
623
|
+
[dotenvx] injecting env (1) from .env
|
|
624
|
+
DATABASE_URL postgres://yourusername@localhost/my_database
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
</details>
|
|
628
|
+
* <details><summary>`run` - Shell Expansion</summary><br>
|
|
629
|
+
|
|
630
|
+
Prevent your shell from expanding inline `$VARIABLES` before dotenvx has a chance to inject it. Use a subshell.
|
|
631
|
+
|
|
632
|
+
```sh
|
|
633
|
+
$ dotenvx run --env="HELLO=World" -- sh -c 'echo Hello $HELLO'
|
|
634
|
+
Hello World
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
</details>
|
|
638
|
+
* <details><summary>`run` - multiple `-f` flags</summary><br>
|
|
639
|
+
|
|
640
|
+
Compose multiple `.env` files for environment variables loading, as you need.
|
|
641
|
+
|
|
642
|
+
```sh
|
|
643
|
+
$ echo "HELLO=local" > .env.local
|
|
644
|
+
$ echo "HELLO=World" > .env
|
|
645
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
646
|
+
|
|
647
|
+
$ dotenvx run -f .env.local -f .env -- node index.js
|
|
648
|
+
[dotenvx] injecting env (1) from .env.local, .env
|
|
649
|
+
Hello local
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
</details>
|
|
653
|
+
* <details><summary>`run --env HELLO=String`</summary><br>
|
|
654
|
+
|
|
655
|
+
Set environment variables as a simple `KEY=value` string pair.
|
|
656
|
+
|
|
657
|
+
```sh
|
|
658
|
+
$ echo "HELLO=World" > .env
|
|
659
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
660
|
+
|
|
661
|
+
$ dotenvx run --env HELLO=String -f .env -- node index.js
|
|
662
|
+
[dotenvx] injecting env (1) from .env, and --env flag
|
|
663
|
+
Hello String
|
|
664
|
+
```
|
|
665
|
+
|
|
666
|
+
</details>
|
|
667
|
+
* <details><summary>`run --overload`</summary><br>
|
|
668
|
+
|
|
669
|
+
Override existing env variables. These can be variables already on your machine or variables loaded as files consecutively. The last variable seen will 'win'.
|
|
670
|
+
|
|
671
|
+
```sh
|
|
672
|
+
$ echo "HELLO=local" > .env.local
|
|
673
|
+
$ echo "HELLO=World" > .env
|
|
674
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
675
|
+
|
|
676
|
+
$ dotenvx run -f .env.local -f .env --overload -- node index.js
|
|
677
|
+
[dotenvx] injecting env (1) from .env.local, .env
|
|
678
|
+
Hello World
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
</details>
|
|
682
|
+
* <details><summary>`DOTENV_PRIVATE_KEY=key run`</summary><br>
|
|
683
|
+
|
|
684
|
+
Decrypt your encrypted `.env` by setting `DOTENV_PRIVATE_KEY` before `dotenvx run`.
|
|
685
|
+
|
|
686
|
+
```sh
|
|
687
|
+
$ touch .env
|
|
688
|
+
$ dotenvx set HELLO encrypted --encrypt
|
|
689
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
690
|
+
|
|
691
|
+
# check your .env.keys files for your privateKey
|
|
692
|
+
$ DOTENV_PRIVATE_KEY="122...0b8" dotenvx run -- node index.js
|
|
693
|
+
[dotenvx] injecting env (2) from .env
|
|
694
|
+
Hello encrypted
|
|
695
|
+
```
|
|
696
|
+
|
|
697
|
+
</details>
|
|
698
|
+
* <details><summary>`DOTENV_PRIVATE_KEY_PRODUCTION=key run`</summary><br>
|
|
699
|
+
|
|
700
|
+
Decrypt your encrypted `.env.production` by setting `DOTENV_PRIVATE_KEY_PRODUCTION` before `dotenvx run`. Alternatively, this can be already set on your server or cloud provider.
|
|
701
|
+
|
|
702
|
+
```sh
|
|
703
|
+
$ touch .env.production
|
|
704
|
+
$ dotenvx set HELLO "production encrypted" -f .env.production --encrypt
|
|
705
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
706
|
+
|
|
707
|
+
# check .env.keys for your privateKey
|
|
708
|
+
$ DOTENV_PRIVATE_KEY_PRODUCTION="122...0b8" dotenvx run -- node index.js
|
|
709
|
+
[dotenvx] injecting env (2) from .env.production
|
|
710
|
+
Hello production encrypted
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
Note the `DOTENV_PRIVATE_KEY_PRODUCTION` ends with `_PRODUCTION`. This instructs dotenvx run to load the `.env.production` file.
|
|
714
|
+
|
|
715
|
+
</details>
|
|
716
|
+
* <details><summary>`DOTENV_PRIVATE_KEY_CI=key dotenvx run`</summary><br>
|
|
717
|
+
|
|
718
|
+
Decrypt your encrypted `.env.ci` by setting `DOTENV_PRIVATE_KEY_CI` before `dotenvx run`. Alternatively, this can be already set on your server or cloud provider.
|
|
719
|
+
|
|
720
|
+
```sh
|
|
721
|
+
$ touch .env.ci
|
|
722
|
+
$ dotenvx set HELLO "ci encrypted" -f .env.production --encrypt
|
|
723
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
724
|
+
|
|
725
|
+
# check .env.keys for your privateKey
|
|
726
|
+
$ DOTENV_PRIVATE_KEY_CI="122...0b8" dotenvx run -- node index.js
|
|
727
|
+
[dotenvx] injecting env (2) from .env.ci
|
|
728
|
+
Hello ci encrypted
|
|
729
|
+
```
|
|
730
|
+
|
|
731
|
+
Note the `DOTENV_PRIVATE_KEY_CI` ends with `_CI`. This instructs dotenvx run to load the `.env.ci` file. See the pattern?
|
|
732
|
+
|
|
733
|
+
</details>
|
|
734
|
+
* <details><summary>`DOTENV_PRIVATE_KEY=key DOTENV_PRIVATE_KEY_PRODUCTION=key run` - Combine Multiple</summary><br>
|
|
735
|
+
|
|
736
|
+
Decrypt your encrypted `.env` and `.env.production` files by setting `DOTENV_PRIVATE_KEY` and `DOTENV_PRIVATE_KEY_PRODUCTION` before `dotenvx run`.
|
|
737
|
+
|
|
738
|
+
```sh
|
|
739
|
+
$ touch .env
|
|
740
|
+
$ touch .env.production
|
|
741
|
+
$ dotenvx set HELLO encrypted --encrypt
|
|
742
|
+
$ dotenvx set HELLO "production encrypted" -f .env.production --encrypt
|
|
743
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
744
|
+
|
|
745
|
+
# check .env.keys for your privateKeys
|
|
746
|
+
$ DOTENV_PRIVATE_KEY="122...0b8" DOTENV_PRIVATE_KEY_PRODUCTION="122...0b8" dotenvx run -- node index.js
|
|
747
|
+
[dotenvx] injecting env (3) from .env, .env.production
|
|
748
|
+
Hello encrypted
|
|
749
|
+
|
|
750
|
+
$ DOTENV_PRIVATE_KEY_PRODUCTION="122...0b8" DOTENV_PRIVATE_KEY="122...0b8" dotenvx run -- node index.js
|
|
751
|
+
[dotenvx] injecting env (3) from .env.production, .env
|
|
752
|
+
Hello production encrypted
|
|
753
|
+
```
|
|
754
|
+
|
|
755
|
+
Compose any encrypted files you want this way. As long as a `DOTENV_PRIVATE_KEY_${environment}` is set, the values from `.env.${environment}` will be decrypted at runtime.
|
|
756
|
+
|
|
757
|
+
</details>
|
|
758
|
+
* <details><summary>`run --verbose`</summary><br>
|
|
759
|
+
|
|
760
|
+
Set log level to `verbose`. ([log levels](https://github.com/winstonjs/winston?tab=readme-ov-file#logging))
|
|
761
|
+
|
|
762
|
+
```sh
|
|
763
|
+
$ echo "HELLO=production" > .env.production
|
|
764
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
765
|
+
|
|
766
|
+
$ dotenvx run -f .env.production --verbose -- node index.js
|
|
767
|
+
loading env from .env.production (/path/to/.env.production)
|
|
768
|
+
HELLO set
|
|
769
|
+
[dotenvx] injecting env (1) from .env.production
|
|
770
|
+
Hello production
|
|
771
|
+
```
|
|
772
|
+
|
|
773
|
+
</details>
|
|
774
|
+
* <details><summary>`run --debug`</summary><br>
|
|
775
|
+
|
|
776
|
+
Set log level to `debug`. ([log levels](https://github.com/winstonjs/winston?tab=readme-ov-file#logging))
|
|
777
|
+
|
|
778
|
+
```sh
|
|
779
|
+
$ echo "HELLO=production" > .env.production
|
|
780
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
781
|
+
|
|
782
|
+
$ dotenvx run -f .env.production --debug -- node index.js
|
|
783
|
+
process command [node index.js]
|
|
784
|
+
options: {"env":[],"envFile":[".env.production"]}
|
|
785
|
+
loading env from .env.production (/path/to/.env.production)
|
|
786
|
+
{"HELLO":"production"}
|
|
787
|
+
HELLO set
|
|
788
|
+
HELLO set to production
|
|
789
|
+
[dotenvx] injecting env (1) from .env.production
|
|
790
|
+
executing process command [node index.js]
|
|
791
|
+
expanding process command to [/opt/homebrew/bin/node index.js]
|
|
792
|
+
Hello production
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
</details>
|
|
796
|
+
* <details><summary>`run --quiet`</summary><br>
|
|
797
|
+
|
|
798
|
+
Use `--quiet` to suppress all output (except errors). ([log levels](https://github.com/winstonjs/winston?tab=readme-ov-file#logging))
|
|
799
|
+
|
|
800
|
+
```sh
|
|
801
|
+
$ echo "HELLO=production" > .env.production
|
|
802
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
803
|
+
|
|
804
|
+
$ dotenvx run -f .env.production --quiet -- node index.js
|
|
805
|
+
Hello production
|
|
806
|
+
```
|
|
807
|
+
|
|
808
|
+
</details>
|
|
809
|
+
* <details><summary>`run --log-level`</summary><br>
|
|
810
|
+
|
|
811
|
+
Set `--log-level` to whatever you wish. For example, to supress warnings (risky), set log level to `error`:
|
|
812
|
+
|
|
813
|
+
```sh
|
|
814
|
+
$ echo "HELLO=production" > .env.production
|
|
815
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
816
|
+
|
|
817
|
+
$ dotenvx run -f .env.production --log-level=error -- node index.js
|
|
818
|
+
Hello production
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
Available log levels are `error, warn, info, verbose, debug, silly` ([source](https://github.com/winstonjs/winston?tab=readme-ov-file#logging))
|
|
822
|
+
|
|
823
|
+
</details>
|
|
824
|
+
* <details><summary>`run --convention=nextjs`</summary><br>
|
|
825
|
+
|
|
826
|
+
Load envs using [Next.js' convention](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order). Set `--convention` to `nextjs`:
|
|
827
|
+
|
|
828
|
+
```sh
|
|
829
|
+
$ echo "HELLO=development local" > .env.development.local
|
|
830
|
+
$ echo "HELLO=local" > .env.local
|
|
831
|
+
$ echo "HELLO=development" > .env.development
|
|
832
|
+
$ echo "HELLO=env" > .env
|
|
833
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
834
|
+
|
|
835
|
+
$ dotenvx run --convention=nextjs -- node index.js
|
|
836
|
+
[dotenvx] injecting env (1) from .env.development.local, .env.local, .env.development, .env
|
|
837
|
+
Hello development local
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
(more conventions available upon request)
|
|
841
|
+
|
|
842
|
+
</details>
|
|
843
|
+
* <details><summary>`get KEY`</summary><br>
|
|
844
|
+
|
|
845
|
+
Return a single environment variable's value.
|
|
846
|
+
|
|
847
|
+
```sh
|
|
848
|
+
$ echo "HELLO=World" > .env
|
|
849
|
+
|
|
850
|
+
$ dotenvx get HELLO
|
|
851
|
+
World
|
|
852
|
+
```
|
|
853
|
+
|
|
854
|
+
</details>
|
|
855
|
+
* <details><summary>`get KEY -f`</summary><br>
|
|
856
|
+
|
|
857
|
+
Return a single environment variable's value from a specific `.env` file.
|
|
858
|
+
|
|
859
|
+
```sh
|
|
860
|
+
$ echo "HELLO=World" > .env
|
|
861
|
+
$ echo "HELLO=production" > .env.production
|
|
862
|
+
|
|
863
|
+
$ dotenvx get HELLO -f .env.production
|
|
864
|
+
production
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
</details>
|
|
868
|
+
* <details><summary>`get KEY --env`</summary><br>
|
|
590
869
|
|
|
591
|
-
|
|
870
|
+
Return a single environment variable's value from a `--env` string.
|
|
592
871
|
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
872
|
+
```sh
|
|
873
|
+
$ dotenvx get HELLO --env HELLO=String -f .env.production
|
|
874
|
+
String
|
|
875
|
+
```
|
|
876
|
+
|
|
877
|
+
</details>
|
|
878
|
+
|
|
879
|
+
* <details><summary>`get KEY --overload`</summary><br>
|
|
880
|
+
|
|
881
|
+
Return a single environment variable's value where each found value is overloaded.
|
|
882
|
+
|
|
883
|
+
```sh
|
|
884
|
+
$ echo "HELLO=World" > .env
|
|
885
|
+
$ echo "HELLO=production" > .env.production
|
|
886
|
+
|
|
887
|
+
$ dotenvx get HELLO -f .env.production --env HELLO=String -f .env --overload
|
|
888
|
+
World
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
</details>
|
|
892
|
+
* <details><summary>`get KEY --convention=nextjs`</summary><br>
|
|
893
|
+
|
|
894
|
+
Return a single environment variable's value using [Next.js' convention](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order). Set `--convention` to `nextjs`:
|
|
895
|
+
|
|
896
|
+
```sh
|
|
897
|
+
$ echo "HELLO=development local" > .env.development.local
|
|
898
|
+
$ echo "HELLO=local" > .env.local
|
|
899
|
+
$ echo "HELLO=development" > .env.development
|
|
900
|
+
$ echo "HELLO=env" > .env
|
|
901
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
902
|
+
|
|
903
|
+
$ dotenvx get HELLO --convention=nextjs
|
|
904
|
+
development local
|
|
905
|
+
```
|
|
906
|
+
|
|
907
|
+
</details>
|
|
908
|
+
* <details><summary>`get` (json)</summary><br>
|
|
909
|
+
|
|
910
|
+
Return a json response of all key/value pairs in a `.env` file.
|
|
911
|
+
|
|
912
|
+
```sh
|
|
913
|
+
$ echo "HELLO=World" > .env
|
|
914
|
+
|
|
915
|
+
$ dotenvx get
|
|
916
|
+
{"HELLO":"World"}
|
|
917
|
+
```
|
|
918
|
+
|
|
919
|
+
</details>
|
|
920
|
+
* <details><summary>`get --all`</summary><br>
|
|
921
|
+
|
|
922
|
+
Return preset machine envs as well.
|
|
923
|
+
|
|
924
|
+
```sh
|
|
925
|
+
$ echo "HELLO=World" > .env
|
|
926
|
+
|
|
927
|
+
$ dotenvx get --all
|
|
928
|
+
{"PWD":"/some/file/path","USER":"username","LIBRARY_PATH":"/usr/local/lib", ..., "HELLO":"World"}
|
|
929
|
+
```
|
|
930
|
+
|
|
931
|
+
</details>
|
|
932
|
+
* <details><summary>`get --all --pretty-print`</summary><br>
|
|
933
|
+
|
|
934
|
+
Make the output more readable - pretty print it.
|
|
935
|
+
|
|
936
|
+
```sh
|
|
937
|
+
$ echo "HELLO=World" > .env
|
|
938
|
+
|
|
939
|
+
$ dotenvx get --all --pretty-print
|
|
940
|
+
{
|
|
941
|
+
"PWD": "/some/filepath",
|
|
942
|
+
"USER": "username",
|
|
943
|
+
"LIBRARY_PATH": "/usr/local/lib",
|
|
944
|
+
...,
|
|
945
|
+
"HELLO": "World"
|
|
946
|
+
}
|
|
947
|
+
```
|
|
948
|
+
|
|
949
|
+
</details>
|
|
950
|
+
* <details><summary>`set KEY value`</summary><br>
|
|
951
|
+
|
|
952
|
+
Set a single key/value.
|
|
953
|
+
|
|
954
|
+
```sh
|
|
955
|
+
$ touch .env
|
|
956
|
+
|
|
957
|
+
$ dotenvx set HELLO World
|
|
958
|
+
set HELLO (.env)
|
|
959
|
+
```
|
|
960
|
+
|
|
961
|
+
</details>
|
|
962
|
+
* <details><summary>`set KEY value --encrypt`</summary><br>
|
|
963
|
+
|
|
964
|
+
Set an encrypted key/value.
|
|
965
|
+
|
|
966
|
+
```sh
|
|
967
|
+
$ touch .env
|
|
968
|
+
|
|
969
|
+
$ dotenvx set HELLO World --encrypt
|
|
970
|
+
set HELLO with encryption (.env)
|
|
971
|
+
```
|
|
972
|
+
|
|
973
|
+
</details>
|
|
974
|
+
* <details><summary>`set KEY value -f`</summary><br>
|
|
975
|
+
|
|
976
|
+
Set an (encrypted) key/value for another `.env` file.
|
|
977
|
+
|
|
978
|
+
```sh
|
|
979
|
+
$ touch .env.production
|
|
980
|
+
|
|
981
|
+
$ dotenvx set HELLO production --encrypt -f .env.production
|
|
982
|
+
set HELLO with encryption (.env.production)
|
|
983
|
+
```
|
|
984
|
+
|
|
985
|
+
</details>
|
|
986
|
+
* <details><summary>`set KEY "value with spaces"`</summary><br>
|
|
987
|
+
|
|
988
|
+
Set a value containing spaces.
|
|
989
|
+
|
|
990
|
+
```sh
|
|
991
|
+
$ touch .env.ci
|
|
992
|
+
|
|
993
|
+
$ dotenvx set HELLO "my ci" -f .env.ci
|
|
994
|
+
set HELLO (.env.ci)
|
|
995
|
+
```
|
|
996
|
+
|
|
997
|
+
</details>
|
|
998
|
+
* <details><summary>`ls`</summary><br>
|
|
999
|
+
|
|
1000
|
+
Print all `.env` files in a tree structure.
|
|
1001
|
+
|
|
1002
|
+
```sh
|
|
1003
|
+
$ touch .env
|
|
1004
|
+
$ touch .env.production
|
|
1005
|
+
$ mkdir -p apps/backend
|
|
1006
|
+
$ touch apps/backend/.env
|
|
1007
|
+
|
|
1008
|
+
$ dotenvx ls
|
|
1009
|
+
├─ .env.production
|
|
1010
|
+
├─ .env
|
|
1011
|
+
└─ apps
|
|
1012
|
+
└─ backend
|
|
1013
|
+
└─ .env
|
|
1014
|
+
```
|
|
1015
|
+
|
|
1016
|
+
</details>
|
|
1017
|
+
* <details><summary>`ls directory`</summary><br>
|
|
1018
|
+
|
|
1019
|
+
Print all `.env` files inside a specified path to a directory.
|
|
1020
|
+
|
|
1021
|
+
```sh
|
|
1022
|
+
$ touch .env
|
|
1023
|
+
$ touch .env.production
|
|
1024
|
+
$ mkdir -p apps/backend
|
|
1025
|
+
$ touch apps/backend/.env
|
|
1026
|
+
|
|
1027
|
+
$ dotenvx ls apps/backend
|
|
1028
|
+
└─ .env
|
|
1029
|
+
```
|
|
1030
|
+
|
|
1031
|
+
</details>
|
|
1032
|
+
* <details><summary>`ls -f`</summary><br>
|
|
598
1033
|
|
|
599
|
-
|
|
1034
|
+
Glob `.env` filenames matching a wildcard.
|
|
600
1035
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
1036
|
+
```sh
|
|
1037
|
+
$ touch .env
|
|
1038
|
+
$ touch .env.production
|
|
1039
|
+
$ mkdir -p apps/backend
|
|
1040
|
+
$ touch apps/backend/.env
|
|
1041
|
+
$ touch apps/backend/.env.prod
|
|
1042
|
+
|
|
1043
|
+
$ dotenvx ls -f **/.env.prod*
|
|
1044
|
+
├─ .env.production
|
|
1045
|
+
└─ apps
|
|
1046
|
+
└─ backend
|
|
1047
|
+
└─ .env.prod
|
|
1048
|
+
```
|
|
1049
|
+
|
|
1050
|
+
</details>
|
|
1051
|
+
* <details><summary>`genexample`</summary><br>
|
|
1052
|
+
|
|
1053
|
+
In one command, generate a `.env.example` file from your current `.env` file contents.
|
|
1054
|
+
|
|
1055
|
+
```sh
|
|
1056
|
+
$ echo "HELLO=World" > .env
|
|
1057
|
+
|
|
1058
|
+
$ dotenvx genexample
|
|
1059
|
+
✔ updated .env.example (1)
|
|
1060
|
+
```
|
|
1061
|
+
|
|
1062
|
+
```ini
|
|
1063
|
+
# .env.example
|
|
1064
|
+
HELLO=""
|
|
1065
|
+
```
|
|
1066
|
+
|
|
1067
|
+
</details>
|
|
1068
|
+
* <details><summary>`genexample -f`</summary><br>
|
|
1069
|
+
|
|
1070
|
+
Pass multiple `.env` files to generate your `.env.example` file from the combination of their contents.
|
|
1071
|
+
|
|
1072
|
+
```sh
|
|
1073
|
+
$ echo "HELLO=World" > .env
|
|
1074
|
+
$ echo "DB_HOST=example.com" > .env.production
|
|
1075
|
+
|
|
1076
|
+
$ dotenvx genexample -f .env -f .env.production
|
|
1077
|
+
✔ updated .env.example (2)
|
|
1078
|
+
```
|
|
1079
|
+
|
|
1080
|
+
```ini
|
|
1081
|
+
# .env.example
|
|
1082
|
+
HELLO=""
|
|
1083
|
+
DB_HOST=""
|
|
1084
|
+
```
|
|
1085
|
+
|
|
1086
|
+
</details>
|
|
1087
|
+
* <details><summary>`genexample directory`</summary><br>
|
|
1088
|
+
|
|
1089
|
+
Generate a `.env.example` file inside the specified directory. Useful for monorepos.
|
|
1090
|
+
|
|
1091
|
+
```sh
|
|
1092
|
+
$ echo "HELLO=World" > .env
|
|
1093
|
+
$ mkdir -p apps/backend
|
|
1094
|
+
$ echo "HELLO=Backend" > apps/backend/.env
|
|
1095
|
+
|
|
1096
|
+
$ dotenvx genexample apps/backend
|
|
1097
|
+
✔ updated .env.example (1)
|
|
1098
|
+
```
|
|
1099
|
+
|
|
1100
|
+
```ini
|
|
1101
|
+
# apps/backend/.env.example
|
|
1102
|
+
HELLO=""
|
|
1103
|
+
```
|
|
1104
|
+
|
|
1105
|
+
</details>
|
|
1106
|
+
* <details><summary>`gitignore`</summary><br>
|
|
1107
|
+
|
|
1108
|
+
Gitignore your `.env` files.
|
|
1109
|
+
|
|
1110
|
+
```sh
|
|
1111
|
+
$ dotenvx gitignore
|
|
1112
|
+
creating .gitignore
|
|
1113
|
+
appending .env* to .gitignore
|
|
1114
|
+
done
|
|
1115
|
+
```
|
|
1116
|
+
|
|
1117
|
+
</details>
|
|
1118
|
+
* <details><summary>`precommit`</summary><br>
|
|
1119
|
+
|
|
1120
|
+
Prevent `.env` files from being committed to code.
|
|
1121
|
+
|
|
1122
|
+
```sh
|
|
1123
|
+
$ dotenvx precommit
|
|
1124
|
+
[dotenvx][precommit] success
|
|
1125
|
+
```
|
|
1126
|
+
|
|
1127
|
+
</details>
|
|
1128
|
+
* <details><summary>`precommit --install`</summary><br>
|
|
1129
|
+
|
|
1130
|
+
Install a shell script to `.git/hooks/pre-commit` to prevent accidentally committing any `.env` files to source control.
|
|
1131
|
+
|
|
1132
|
+
```sh
|
|
1133
|
+
$ dotenvx precommit --install
|
|
1134
|
+
[dotenvx][precommit] dotenvx precommit installed [.git/hooks/pre-commit]
|
|
1135
|
+
```
|
|
1136
|
+
|
|
1137
|
+
</details>
|
|
1138
|
+
* <details><summary>`prebuild`</summary><br>
|
|
1139
|
+
|
|
1140
|
+
Prevent `.env` files from being built into your docker containers.
|
|
1141
|
+
|
|
1142
|
+
Add it to your `Dockerfile`.
|
|
1143
|
+
|
|
1144
|
+
```sh
|
|
1145
|
+
RUN curl -fsS https://dotenvx.sh/ | sh
|
|
1146
|
+
|
|
1147
|
+
...
|
|
1148
|
+
|
|
1149
|
+
RUN dotenvx prebuild
|
|
1150
|
+
CMD ["dotenvx", "run", "--", "node", "index.js"]
|
|
1151
|
+
```
|
|
1152
|
+
|
|
1153
|
+
</details>
|
|
1154
|
+
* <details><summary>`scan`</summary><br>
|
|
1155
|
+
|
|
1156
|
+
Use [gitleaks](https://gitleaks.io) under the hood to scan for possible secrets in your code.
|
|
1157
|
+
|
|
1158
|
+
```sh
|
|
1159
|
+
$ dotenvx scan
|
|
1160
|
+
|
|
1161
|
+
○
|
|
1162
|
+
│╲
|
|
1163
|
+
│ ○
|
|
1164
|
+
○ ░
|
|
1165
|
+
░ gitleaks
|
|
1166
|
+
|
|
1167
|
+
100 commits scanned.
|
|
1168
|
+
no leaks found
|
|
1169
|
+
```
|
|
1170
|
+
|
|
1171
|
+
</details>
|
|
1172
|
+
* <details><summary>`help`</summary><br>
|
|
1173
|
+
|
|
1174
|
+
Output help for `dotenvx`.
|
|
1175
|
+
|
|
1176
|
+
```sh
|
|
1177
|
+
$ dotenvx help
|
|
1178
|
+
Usage: @dotenvx/dotenvx [options] [command]
|
|
1179
|
+
|
|
1180
|
+
a better dotenv–from the creator of `dotenv`
|
|
1181
|
+
|
|
1182
|
+
Options:
|
|
1183
|
+
-l, --log-level <level> set log level (default: "info")
|
|
1184
|
+
-q, --quiet sets log level to error
|
|
1185
|
+
-v, --verbose sets log level to verbose
|
|
1186
|
+
-d, --debug sets log level to debug
|
|
1187
|
+
-V, --version output the version number
|
|
1188
|
+
-h, --help display help for command
|
|
1189
|
+
|
|
1190
|
+
Commands:
|
|
1191
|
+
run [options] inject env at runtime [dotenvx run -- yourcommand]
|
|
1192
|
+
get [options] [key] return a single environment variable
|
|
1193
|
+
set [options] <KEY> <value> set a single environment variable
|
|
1194
|
+
...
|
|
1195
|
+
help [command] display help for command
|
|
1196
|
+
```
|
|
1197
|
+
|
|
1198
|
+
You can get more detailed help per command with `dotenvx help COMMAND`.
|
|
1199
|
+
|
|
1200
|
+
```sh
|
|
1201
|
+
$ dotenvx help run
|
|
1202
|
+
Usage: @dotenvx/dotenvx run [options]
|
|
1203
|
+
|
|
1204
|
+
inject env at runtime [dotenvx run -- yourcommand]
|
|
1205
|
+
|
|
1206
|
+
Options:
|
|
1207
|
+
-e, --env <strings...> environment variable(s) set as string (example: "HELLO=World") (default: [])
|
|
1208
|
+
-f, --env-file <paths...> path(s) to your env file(s) (default: [])
|
|
1209
|
+
-fv, --env-vault-file <paths...> path(s) to your .env.vault file(s) (default: [])
|
|
1210
|
+
-o, --overload override existing env variables
|
|
1211
|
+
--convention <name> load a .env convention (available conventions: ['nextjs'])
|
|
1212
|
+
-h, --help display help for command
|
|
1213
|
+
|
|
1214
|
+
Examples:
|
|
1215
|
+
|
|
1216
|
+
$ dotenvx run -- npm run dev
|
|
1217
|
+
$ dotenvx run -- flask --app index run
|
|
1218
|
+
$ dotenvx run -- php artisan serve
|
|
1219
|
+
$ dotenvx run -- bin/rails s
|
|
1220
|
+
|
|
1221
|
+
Try it:
|
|
1222
|
+
|
|
1223
|
+
$ echo "HELLO=World" > .env
|
|
1224
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
1225
|
+
|
|
1226
|
+
$ dotenvx run -- node index.js
|
|
1227
|
+
[dotenvx] injecting env (1) from .env
|
|
1228
|
+
Hello World
|
|
1229
|
+
```
|
|
1230
|
+
|
|
1231
|
+
</details>
|
|
1232
|
+
* <details><summary>`--version`</summary><br>
|
|
1233
|
+
|
|
1234
|
+
Check current version of `dotenvx`.
|
|
1235
|
+
|
|
1236
|
+
```sh
|
|
1237
|
+
$ dotenvx --version
|
|
1238
|
+
X.X.X
|
|
1239
|
+
```
|
|
1240
|
+
|
|
1241
|
+
</details>
|
|
606
1242
|
|
|
607
1243
|
|
|
608
1244
|
|
package/package.json
CHANGED