copy-env-cli
v1.0.0
Published
A tiny command-line interface (CLI) to copy `.env.example` to `.env` in the current working directory if the `.env` file doesn't exist yet.
Downloads
77
Readme
copy-env-cli
📜 About
A tiny command-line interface (CLI) to copy .env.example
to .env
in the current working directory if the .env
file doesn't exist yet. Useful to facilitate the installation of your application by setting default environment variables while leaving the .env
file ignored.
💾 Install
npm install --save-dev copy-env-cli
⚙️ Usage
CLI
copy-env-cli
package.json
{
...
"scripts": {
"postinstall": "copy-env-cli"
}
...
}
Source code
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const cwd = process.cwd()
const envPath = path.join(cwd, '.env')
const envExamplePath = path.join(cwd, '.env.example')
if (!fs.existsSync(envPath) && fs.existsSync(envExamplePath)) {
fs.copyFileSync(envExamplePath, envPath)
}
📄 License
MIT