Create and edit
.env
files via CLI prompts.
Node.js >= 6
is required. To install, type this at the command line:
npm install dotenv-prompt
A dual file convention is used, consisting of .env.sample
and .env
. Both file names and the paths to them can be customized.
.env.sample
should contain a template of default values for environmental variables. This file should be committed to your project's repository. Here is an example of such a file:
SOME_VAR=alue
# Comment
ANOTHER_VAR=another value
This function will read the contents of the file at envSamplePath
if the file at envPath
does not exist. Regardless of which is used, each variable name found within will be prompted for a value.
Optionally, you can specify exactly which should be prompted via varnames
.
When all prompts have been answered, a new file will be written (or overwritten) at envPath
. Any other custom changes made to the pre-existing file will be preserved.
const dotenvPrompt = require('dotenv-prompt');
dotenvPrompt().catch(error => {
console.error(error);
process.exitCode = 1;
});