1 year ago
Tues Jul 25, 2023 5:15pm PST
Show HN: Dotenv-generator – a better way to setup .env files
So after being a fan of Setup.exe-s since I installed my first program 20+ years ago I always hated how manual project setup (usually configuring the env variables) usually is. This package ought to help with that (at least with setting up .env files) by making it interactive. This usually isn't meant for people/projects who have gone through the setup manually multiple times and know what values they need to use, but instead it is meant for people configuring projects for the first time (think new employees being onboarded or a project like aws being configured after installation).

The interactivity is not the only helpful feature, you can use comments in .env files to help the end user understand what values are expected as these comments will be displayed during the setup flow. If you do not provide a comment, a helpful description will be autogenerated using the default/example value.

The easiest way to use this package is to run it (Duh). You can add a `configure` script to your package.json file that runs `dotenv-generator`. If you want users to execute this script let them know by asking them to perform this after installation `npm explore {name_of_the_package} -- npm run configure`.

Ideally your project should use `dotenv-generator --postinstall` as a `postinstall` action. This means that after installation of your package, `dotenv-generator` will be run. This allows for a seamless setup of your project that will magically happen after installation. Since this is not an ideal world npm 6+ *doesn't play nice* with interactive `postinstall` hooks so I've added a check for that if you include the `--postinstall` flag it will check the npm version and for npm 6+ the script won't execute the interactive flow.It will instead print a message saying that the configuration could be done by executing `npm explore {name_of_the_package} -- npm run postinstall`. To view this output you must include `--foreground-scripts` as a flag for package installation ie. `npm i --foreground-scripts`.

The project is fully open sourced here https://github.com/lnenad/dotenv-generator

read article
comments:
add comment
loading comments...