NewNode Dependency Injection v4 is now available.Ver en npm ->

Documentation

CLI Tools

CLI Tools

The ndi command-line tool lets you create configuration files, inspect services, validate your container, and export dependency graphs — all without writing a single line of code.

Installation

The CLI is included when you install the package:

npm install node-dependency-injection

The ndi binary is then available in ./node_modules/.bin/ndi, or globally if you install with -g.

Commands overview

CommandDescription
config:createCreate an empty configuration file
config:checkCheck a configuration file for syntax errors
container:serviceInspect a single service definition
container:graphExport the service dependency graph
container:validateValidate the full service container

config:create

Creates an empty configuration file in the format of your choice.

ndi config:create <path> [options]

Arguments

ArgumentDescription
<path>Directory where the configuration file will be created

Options

OptionDefaultDescription
-n, --name <name>servicesFile name (without extension)
-f, --format <format>yamlFile format: yaml, json, js, xml

Examples

# Create services.yaml in ./config
ndi config:create ./config

# Create my-services.json in ./config
ndi config:create ./config --name my-services --format json

config:check

Loads a configuration file and reports any syntax or parsing errors.

ndi config:check <path>

Arguments

ArgumentDescription
<path>Path to the configuration file (.yaml, .json, .js, or .xml)

The format is detected automatically from the file extension.

Exit codes

CodeMeaning
0File is valid
1File contains errors

Example

ndi config:check ./config/services.yaml

container:service

Displays detailed information about a single registered service.

ndi container:service <path> <service>

Arguments

ArgumentDescription
<path>Path to the configuration file
<service>Service ID to inspect

Example

ndi container:service ./config/services.yaml mailer

The output is a table showing the service's class, arguments, public flag, method calls, tags, properties, laziness, deprecated message, factory, synthetic flag, decoration, shared scope, and parent.


container:graph

Exports the service dependency graph in one of several formats.

ndi container:graph <path> [options]

Arguments

ArgumentDescription
<path>Path to the configuration file

Options

OptionDefaultDescription
--format <format>mermaidOutput format: mermaid, dot, or json
--filter <pattern>Keep only services whose ID matches this regex
--tag <name>Keep only services that have the given tag
--root <id>Show graph starting from this root service
--depth <number>unlimitedMaximum traversal depth when --root is set
--exclude-privatefalseExclude services marked as private

Examples

# Print a Mermaid diagram to stdout
ndi container:graph ./config/services.yaml

# Export as Graphviz DOT
ndi container:graph ./config/services.yaml --format dot

# Export as JSON, filtered to the payment group
ndi container:graph ./config/services.yaml --format json --filter '^payment\.'

# Show only the subtree of 'checkout', 2 levels deep
ndi container:graph ./config/services.yaml --root checkout --depth 2

# Pipe a Mermaid diagram into a file
ndi container:graph ./config/services.yaml > graph.mmd

See the Graph Exporter guide for details on the output formats and filtering options.


container:validate

Compiles and validates the full service container, reporting errors, warnings, and informational messages.

ndi container:validate <path> [options]

Arguments

ArgumentDescription
<path>Path to the configuration file

Options

OptionDefaultDescription
--strictfalseExit with code 1 on warnings as well as errors
--format <format>textOutput format: text or json

Exit codes

CodeMeaning
0Container is valid (no errors; no warnings when --strict is used)
1Container has errors (or warnings in --strict mode)

Examples

# Validate with human-readable output
ndi container:validate ./config/services.yaml

# Validate in strict mode (warnings also fail the build)
ndi container:validate ./config/services.yaml --strict

# Machine-readable JSON output (useful in CI pipelines)
ndi container:validate ./config/services.yaml --format json

JSON output shape

{
  "isValid": true,
  "serviceCount": 12,
  "errors": [],
  "warnings": [],
  "info": []
}

Related guides