
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
env2conffile
Advanced tools
env2conffile (name pending): Create configuration file from environment variables
env2conffile (name pending): Create a configuration file from env variables
This project has been renamed to Desublimate and moved to different location.
The new repository will be https://gitlab.com/blissfulreboot/javascript/desublimate and the development will continue under the new name from now on. This will also mean version bump to 2.0.0 as the command name change breaks the compatibility.
Old package env2conffile
will be deprecated in NPM.
Why indeed. This little script was inspired by Gitlab CI and outside of CI/CD, there might not be too much use for this. In CI/CD pipelines it is sometimes useful to generate configuration files depending on the target environment and sometimes using tools such as Ansible or Terraform can be overkill if the intention is to just generate simple files. Since most of the information is relayed via environment variables, templating and/or automatic creation of the said configuration files is a tempting option.
This little script does just that. In CI environment one can define variables for example PRODUCTION_DOMAIN
or STAGING_DOMAIN
and this script does the rest so that just the DOMAIN
part ends up in the configuration file. At simplest the files are
plain JSON or YAML, but can be more complex. For that use case this tool supports Handlebars templates.
npm install -g env2conffile
for global install or npm install env2conffile
for local.
Currently, by default, the tool assumes that all the files are encoded with UTF-8. Support for other character encodings is coming up!
All begin with --
, e.g. --envFile
envFile:
Description: Variable file (dotenv-like). Used for additional variables and is applied AFTER filtering with varPrefix and varSuffix
output:
Description: Output target.
Possible values: file, stdout, stderr
Default value: stdout
outputFile:
Description: Filename and path of the file when using file output. Sets '--output file' automatically.
renderer:
Description: Renderer used to format the configuration.
Possible values: json, yaml, handlebars
Default value: json
template:
Description: Filename and path of the Handlebars template file.
varPrefix:
Description: Variable prefix used to filter the environment variables.
Default value:
varSuffix:
Description: Variable suffix used to filter the environment variables.
Default value:
doNotStrip:
Description: Do not strip prefix and suffix from the environment variable.
Default value: false
ignoreEnvironment:
Description: Ignore the environment variables completely for safety and to clarify that environment is being ignored.
Default value: false
silent:
Description: Suppress all log output.
Default value: false
debug:
Description: Show debug prints.
Now a configuration file can be used to configure the... configuration file creating tool (I honestly did not realize how
meta this is until writing this down :D ). The configuration file is named .e2crc
and must be placed to the working directory.
The order of evaluation for configuration is: 1. Defaults, 2. .e2crc
3. CLI arguments. The configuration file uses JSON
format and the options are the same as when used via CLI (e.g. "envFile": "./.myenv"
or "debug": true
).
env2conffile supports now dotenv-like .env
file. By this I mean that just like with dotenv, the file is placed to the
working directory and variables are defined <KEY>=<VALUE>
, the formatting done to the variables, however, does differentiate
from dotenv. This means that while comments (lines starting with #) are supported, features like quote conversion and multiline
are missing. While it is not guaranteed that at some point down the line the tool would have full dotenv file support, it is
also not guaranteed that it will happen, only time will tell.
By default, env2conffile will look for .env
file, but this can be overridden either in the configuration file or on command line.
Following examples assume that the package is installed globally.
Example using handlebars template:
BAR_SOMETHING_ELSE_FOO=000 BAR_SOMETHING_FOO=123 BAR_SOME=456 SOME_FOO=789 env2conffile --renderer handlebars --varSuffix _FOO --varPrefix BAR_ --template test.hb --output file --outputFile ../foobar
Example with default json output and stdout:
BAR_SOMETHING_ELSE_FOO=000 BAR_SOMETHING_FOO=123 BAR_SOME=456 SOME_FOO=789 env2conffile --varSuffix _FOO --varPrefix BAR_
The evaluation order is:
This way the file can be used to set the default values which then can be overridden with environment variables.
In the configuration file when not using a handlebars template, the prefix and suffix are stripped from the variable name.
FAQs
env2conffile (name pending): Create configuration file from environment variables
We found that env2conffile demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.