Mastering Project Management with Nx: Using Nx commands

How to run Nx commands

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

This lesson preview is part of the The Art of Enterprise Monorepos with Nx and pnpm course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

This video is available to students only
Unlock This Course

Get unlimited access to The Art of Enterprise Monorepos with Nx and pnpm, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course The Art of Enterprise Monorepos with Nx and pnpm
  • [00:00 - 01:26] With NX, we are not limited to executing single commands like build for a specific project such as shared UI. Instead, we have the flexibility to run commands across multiple projects or even all projects within the workspace. This functionality resembles pmp run -r build, where we execute the build command across our projects. In NX, the equivalent approach involves using run many. We'd formulate it as an "X run many", followed by specifying the target, which could be built or test depending on the task at hand. If no parameters are provided, it automatically initiates the build process for all projects. Alternatively, we have the option to specify the projects we want to include. For example, we could list shared -ui followed by a comma and any other projects we wish to include. When using run -many specifically on shared UI, you'll notice that the command only applies to that particular project. This feature serves as a valuable means to selectively filter projects and execute commands tailored to them. Let's test this feature by adding a new project to the model repo. Let's create a new project called shared utils. So run pmp in it. Let's add a simple top-trip file.

    [01:27 - 01:43] Let's also create the test concrete file. And here let's create a simple function.

    [01:44 - 02:09] Let's copy our build command. "change main" to include the index file inside the dist directory.

    [02:10 - 02:26] And we can run this command. We have error, so let's fix it.

    [02:27 - 02:48] Let's install the dependency for the node types. Now let's try to build this app.

    [02:49 - 03:21] As you can see, the app has been built properly. Now let's try to build two projects out of three we have. So nbx and x run many projects. shared UI, comma shared utils.

    [03:22 - 03:32] And then we have to give it a target. Let's try build.

    [03:33 - 04:01] And nx went ahead and built shared UI and shared util projects. In this lesson we learned how to run commands in multiple projects as well as run commands selectively. nx provides the same feature of functions that pmp provided us to build or run commands recursively.