Documentation
CLI Tools
CLI Tools
Generate config files, validate wiring, and inspect container definitions from the terminal.
node-dependency-injection ships with a command-line interface that helps you create and validate configuration files, and inspect service definitions.
After installing the package, the ndi binary is available:
npx ndi --help
ndi config:create
Creates an empty configuration file in the given directory.
ndi config:create [options] <path>
Options
| Option | Default | Description |
|---|---|---|
-n, --name <name> | services | Name of the output file (without extension) |
-f, --format <format> | yaml | Format of the output file (yaml, json, js) |
Examples
# Create services.yaml in the current directory
ndi config:create .
# Create a JSON file named container in src/
ndi config:create --name=container --format=json src/
# Create a JS file
ndi config:create --format=js ./config
ndi config:check
Validates a configuration file and reports any errors. Supports .yaml, .json and .js formats — the format is detected automatically from the file extension.
ndi config:check <path>
Examples
# Check a YAML configuration file
ndi config:check ./config/services.yaml
# Check a JSON configuration file
ndi config:check ./config/services.json
# Check a JS configuration file
ndi config:check ./config/services.js
On success the command exits with code 0. On failure it prints the error message and exits with code 1.
ndi container:service
Displays detailed information about a specific service registered in a configuration file.
ndi container:service <path> <service>
Arguments
| Argument | Description |
|---|---|
path | Path to the configuration file (YAML, JSON or JS) |
service | Service ID to inspect |
Example
ndi container:service ./config/services.yaml app.mailer
The output is a table showing:
- Key — the service ID
- Class Name — the class used to instantiate the service
- Arguments — constructor arguments and their types/IDs
- Public — whether the service is publicly accessible
- Calls — configured method calls (setter injection)
- Tags — tags attached to the service
- Properties — injected properties
- Laziness — whether the service is lazy
ndi container:validate
Validates container configuration and dependency graph with a detailed report.
ndi container:validate [options] <path>
Options
| Option | Default | Description |
|---|---|---|
--format <format> | text | Output format (text, json) |
--strict | false | Exit with code 1 when warnings are present |
Examples
# Human-readable report
ndi container:validate ./config/services.yaml
# JSON output for CI pipelines
ndi container:validate --format=json ./config/services.yaml
# Fail on warnings too
ndi container:validate --strict ./config/services.yaml
Exit codes:
0: no validation errors (and no warnings when--strictis enabled)1: validation errors found, or warnings with--strict
