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

OptionDefaultDescription
-n, --name <name>servicesName of the output file (without extension)
-f, --format <format>yamlFormat 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

ArgumentDescription
pathPath to the configuration file (YAML, JSON or JS)
serviceService 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

OptionDefaultDescription
--format <format>textOutput format (text, json)
--strictfalseExit 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 --strict is enabled)
  • 1: validation errors found, or warnings with --strict