copy-env
v1.0.2
Published
Copy .env keys into .env.example automatically (or file of your choice). Stop manually updating your .env.example every time you add a new environment variable. Run one command and it's done!
Maintainers
Readme
Install
npm i -D copy-envIt's reccomended to keep the -D flag when installing, so the cli is only available as a dev dependency.
Usage
npx copy-envOn first run, it auto-detects your
.envand.env.example, syncs the keys, and creates acopy-env-config.json. If no.envis found, it helps you create or locate one.
You can also add it to your package.json scripts to run it quickly wtih npm run env:
{
"scripts": {
"env": "copy-env"
}
}Flags
| Flag | Description |
|---|---|
| --yes / -y | Skip all prompts, auto-detect everything |
Config
A copy-env-config.json is created in your project root after the first run:
{
"targetEnv": ".env",
"outputExample": ".env.example"
}This file decides which file to read from and which file to write to. You can change it anytime by manually editing the copy-env-config.json file.
For example, to point to files in a specific directory:
{
"targetEnv": "./backend/.env",
"outputExample": "./backend/.env.example"
}By deafult it looks for .env and .env.example in the current directory eg. root directory where the copy-env is installed.
Security and some cool technical details
- Only key names are extracted: values are never read, stored (in memory and on disk), or logged
- Zero dependencies: the cli is built with only nodejs built-in modules no external packages are used
- Stream-based line reader: the file is never fully loaded into memory instead it reads the file line by line and extracts the key names
- Safe as a dev dependency: even if compromised, it cannot access your secrets because it doesn't have access to your project files
Found a issue? Open an issue on GitHub or email me at: [email protected]
License
MIT
