https://github.com/silent-watcher/dotx
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.
https://github.com/silent-watcher/dotx
cli dotenv dotenvx nodejs
Last synced: 10 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/silent-watcher/dotx
- Owner: Silent-Watcher
- Created: 2025-08-09T19:48:11.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2025-08-10T11:21:38.000Z (10 months ago)
- Last Synced: 2025-08-19T15:08:59.478Z (10 months ago)
- Topics: cli, dotenv, dotenvx, nodejs
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/dotxx
- Size: 86.9 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# 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:
```bash
npm install -g dotxx
# or
yarn global add dotxx
```
Or install as a project dependency and use with `npx`:
```bash
# 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`):
```bash
dotx
```
Custom input/output:
```bash
dotx -i ./configs/env.json -o ./deploy/.env.production
# or
dotx --input ./my-env.json --output ./.env.staging
```
CLI options:
* `-i, --input ` — path to JSON input file (default: `./env.json`)
* `-o, --output ` — 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:
```json
{
"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
```
---