Skip to content

dev-hari-prasad/copy-env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

copy-env logo

Copy Env

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!


Install

npm i -D copy-env

It's reccomended to keep the -D flag when installing, so the cli is only available as a dev dependency.


Usage

npx copy-env

On first run, it auto-detects your .env and .env.example, syncs the keys, and creates a copy-env-config.json. If no .env is 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: webdev.byhari@gmail.com

License

MIT

About

Stop manually updating your `.env.example` every time you add a new environment variable. Run one command and copy env auto updates your .env.example! Try it: npx copy-env

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors