dotxx is a tiny CLI that makes it easy to set environment variables from a JSON file into an existing .env-style file using the @dotenvx/dotenvx API.
- Read a structured JSON file and flatten nested keys into
UPPER_SNAKE_CASEenvironment names. - Use
@dotenvx/dotenvxto add/update each variable in a target env file. - Simple CLI with configurable input and output paths.
- Helpful error messages when files are missing.
Install globally so the dotx command is available system-wide:
npm install -g dotxx
# or
yarn global add dotxxOr install as a project dependency and use with npx:
# install locally
npm install --save-dev dotxx
# run
npx dotxxAfter installing globally, users can simply run
dotx.
Default behavior (uses ./env.json → ./.env.production):
dotxCustom input/output:
dotx -i ./configs/env.json -o ./deploy/.env.production
# or
dotx --input ./my-env.json --output ./.env.stagingCLI options:
-i, --input <path>— path to JSON input file (default:./env.json)-o, --output <path>— path to target env file (default:./.env.production)-V, --version— show version-h, --help— show help
Behavior: The CLI checks that both input and target files exist. If either is missing it prints an error, shows help, and exits with a nonzero code.
env.json can contain nested objects. Example:
{
"app": { "name": "my-app", "port": 3000 },
"db": {
"host": "localhost",
"port": 5432,
"credentials": { "user": "postgres", "pass": "secret" }
},
"featureFlag": true,
"timeout": 30
}- Keys are uppercased.
- Nested keys are concatenated with
_. - Values are stringified.
From the example, flattenInput produces:
APP_NAME=my-app
APP_PORT=3000
DB_HOST=localhost
DB_PORT=5432
DB_CREDENTIALS_USER=postgres
DB_CREDENTIALS_PASS=secret
FEATUREFLAG=true
TIMEOUT=30