Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

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.

Notifications You must be signed in to change notification settings

Silent-Watcher/dotx

Repository files navigation

dotxx

dotxx

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.


Features

  • Read a structured JSON file and flatten nested keys into UPPER_SNAKE_CASE environment names.
  • Use @dotenvx/dotenvx to 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

Install globally so the dotx command is available system-wide:

npm install -g dotxx
# or
yarn global add dotxx

Or install as a project dependency and use with npx:

# install locally
npm install --save-dev dotxx
# run
npx dotxx

After installing globally, users can simply run dotx.


Usage

Default behavior (uses ./env.json./.env.production):

dotx

Custom input/output:

dotx -i ./configs/env.json -o ./deploy/.env.production
# or
dotx --input ./my-env.json --output ./.env.staging

CLI 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.


Input format

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
}

Flattening rules

  • 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

About

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.

Topics

Resources

Stars

Watchers

Forks