Skip to content

Executors and configurations

Nx plugins usually infer tasks that run a tool's command-line interface directly. When no plugin can infer a task, configure the command or use an executor for Nx-specific behavior.

Add a command when a target needs to run a shell command. Nx normalizes this shorthand to the nx:run-commands executor.

{
"name": "mylib",
"nx": {
"targets": {
"check-licenses": {
"command": "license-checker --summary",
},
},
},
}

For multiple commands, environment variables, and working-directory options, see the run-commands executor.

An executor is an implementation provided by an Nx plugin. Executors are useful when a task needs behavior that a command alone doesn't provide. Configure one with an executor value in the form <package-name>:<executor-name>.

For example, the @nx/js:node executor coordinates a build target with a running Node.js process. It rebuilds and restarts the process as source files change.

{
"name": "api",
"nx": {
"targets": {
"serve": {
"executor": "@nx/js:node",
"continuous": true,
"dependsOn": ["build"],
"options": {
"buildTarget": "api:build",
},
},
},
},
}

This target contains the following fields:

  • executor identifies the plugin package and executor implementation.
  • options provides default values defined by that executor's schema.
  • continuous tells Nx that the task remains running.

Run an executor-backed target in the same way as any other target:

Terminal window
nx serve api

Browse available executors in the plugin registry.

The configurations property defines named option overrides. Nx merges the selected configuration into options, then applies command-line arguments.

{
"name": "api",
"nx": {
"targets": {
"serve": {
"executor": "@nx/js:node",
"continuous": true,
"dependsOn": ["build"],
"options": {
"buildTarget": "api:build",
},
"configurations": {
"development": {
"buildTarget": "api:build:development",
},
"production": {
"buildTarget": "api:build:production",
},
},
},
},
},
}

Select the configuration with either command form:

Terminal window
nx serve api --configuration=production
nx run api:serve:production

Set defaultConfiguration on the target when one named configuration should apply without the --configuration option. Explicitly selecting another configuration overrides that default.

Create a local executor when your workspace needs reusable task behavior that a command or existing plugin doesn't provide. For the implementation and schema format, see create a local executor.