Skip to content
Tutorial 4/8: Run tasks across your workspace

Help me run tasks in my Nx workspace efficiently.

Use my existing workspace and projects for hands-on examples.

Show me how to run a single task for one project, run multiple tasks across all projects with , and understand how Nx orders task execution. Do not discuss caching or affected commands — those are covered in later tutorials.

Stay on-topic: only teach what's covered on this page. Do not introduce concepts from later tutorials.

Tutorial: https://canary.nx.dev/docs/getting-started/tutorials/running-tasks.md

Help me run tasks in my Nx workspace efficiently.

Use my existing workspace and projects for hands-on examples.

Show me how to run a single task for one project, run multiple tasks across all projects with , and understand how Nx orders task execution. Do not discuss caching or affected commands — those are covered in later tutorials.

Stay on-topic: only teach what's covered on this page. Do not introduce concepts from later tutorials.

Tutorial: https://canary.nx.dev/docs/getting-started/tutorials/running-tasks.md

You've configured your tasks. Now how do you run them, for one project, for many, or only for what changed?

The examples below use Vite and Vitest, but the concepts apply to any tool. Substitute your own build and test commands as needed.

Given a project with tasks defined in package.json (or project.json for non-JS projects):

apps/my-app/package.json
{
"name": "my-app",
"scripts": {
"build": "vite build",
"test": "vitest run",
},
}

Run a task with nx run <project>:<task>:

Terminal window
nx run my-app:build

Or the shorthand, which works when the task name doesn't conflict with an Nx command:

Terminal window
nx build my-app

You can also cd into a project directory and run without specifying the project name:

Terminal window
cd apps/my-app
nx build

Nx resolves the project from the current directory. Try running nx build or nx test in your own workspace to see it in action.

Use run-many to run one or more tasks across multiple projects:

Terminal window
# Run build for all projects that have a build task
nx run-many --targets build
# Run multiple tasks
nx run-many --targets build test lint
# Run tasks for specific projects only
nx run-many --targets build --projects my-app

The -t and -p flags are shorthands for --targets and --projects.

Nx runs tasks in parallel by default, respecting the task dependencies you've configured. For example, with this configuration:

nx.json
{
"targetDefaults": {
"build": {
"dependsOn": ["^build"],
},
},
}

Running nx run-many --targets build builds dependencies first, then dependents:

Diagram showing task execution order: shared-ui:build and utils:build run in step 1, then my-app:build and data-access:build run in step 2, driven by dependsOn configuration

Nx handles the ordering automatically, even when running in parallel.

Pass arguments directly to the task:

Terminal window
# Use a named configuration
nx build my-app --configuration=production
# Forward arguments to the underlying tool
nx test my-app --watch

For more details, see pass args to commands.

By default, Nx runs tasks in parallel. Limit the number of concurrent tasks with --parallel:

Terminal window
nx run-many --targets build --parallel=3

Set --parallel=1 to run tasks sequentially.

Some tasks run indefinitely, like development servers. When another task depends on a continuous task, Nx starts both concurrently. For example, running an e2e test that needs a dev server:

Terminal window
nx run my-app:e2e

This works when e2e depends on a serve task marked as continuous (configured in Configuring Tasks). Nx starts the server, waits for it to be ready, then runs the tests.

Nx Console is a VS Code and WebStorm extension that provides a visual interface for running tasks, exploring your project graph, and managing your workspace, all without memorizing CLI commands.