DEV Community

Cover image for Nx - The fastest growing monorepo solution in the JS ecosystem
Juri Strumpflohner for Nx

Posted on • Updated on

Nx - The fastest growing monorepo solution in the JS ecosystem

EDIT(Sep 9th, 2022): approaching 2.5 million


Nx just crossed 2 million NPM downloads / week (see @nrwl/tao package on npm).

And these are just the public downloads which do not include all the big fortune 500 companies using Nx on a daily basis to power their teams.

But it is not just about the number of downloads, but about the growth: Nx crossed 1 million per week in January 2022 and now 2 million in June 2022.

Nx growth

At this point you might now be wondering: what is Nx and what are monorepos? Let's start with monorepos first.

What is a monorepo?

The term "monorepo" is kind of misleading, but in principle it is a single (usually) Git repository hosting multiple projects. Those projects ideally form relationships among them by sharing and re-using functionality.

Monorepo

The advantage for developers? If done right, increased productivity by being able to directly use shared dependencies rather than going through versioning & publishing to internal registries, being able to easily run cross-cutting experiments, do a refactoring with a single PR rather than coordinating multiple releases & version updates, more visibility to other projects & greater developer mobility among teams. These are just some of the benefits.

The exact setup of a monorepo comes in different shapes, from using a single-version policy approach to colocating packages with their own node_modules folders and applying symlinks for sharing code.

You can learn more at https://monorepo.tools.

What is Nx?

The official slogan: "a smart, fast and extensible build system". Does that mean it is a replacement for Webpack, Vite, SWC or Vite? Not really! At its core Nx is rather an orchestrator that applies these tools in the most efficient way.

Monorepo support is built into Nx's DNA. You can use Nx..

Light-weight and incrementally by leveraging it's powerful task scheduler. This is especially interesting if you already have a yarn/npm/pnpm workspace based monorepo setup and you want to enhance its capabilities. If you happen to use Lerna you might want to read this.

Here's an example for showing the lightweight setup of Nx, by incrementally adding it to an existing Yarn workspaces monorepo:

Using its plugin system which comes with powerful support for Angular, React, Next, Next.js, Node and more. These plugins are more opinionated, but carefully crafted to provide the best possible developer experience and remove the burden of a manual tooling setup. Furthermore it comes with advanced features such as automated module federation setup or automated code migrations, a feature that is highly appreciated by large enterprises which otherwise struggle to keep their tooling up to date.

Here's an example of developing a React application using Nx's powerful plugin system:

Learn more at nx.dev and on Youtube. You might also find this free Egghead course interesting.

How does Nx compare to other monorepo tools in the space?

  • Nx offers the full spectrum, allowing for an incremental and lightweight adoption to providing a more complete and preconfigured experience based on plugins. It does not just help setup a monorepo and execute tasks, but also guides developers throughout the development lifecycle.
  • Nx is faster than most of the current available alternatives. See the corresponding benchmark repository
  • Nx provides the ability to distribute the execution of tasks efficiently across multiple machines, known as Distributed Task Execution (DTE). This is possible via Nx Cloud and provides major performance improvements on CI.
  • Nx has a particular focus on the developer experience. A dedicated VSCode extension and a beautiful terminal output are just two examples for that.
  • Nx is extensible, coming with its own devkit which allows to fully customize and tailor the Nx experience to your own needs.

Nx Community

There's a large community behind Nx which can be found at https://nx.dev/community.


Learn more

🧠 Nx Docs
πŸ‘©β€πŸ’» Nx GitHub
πŸ’¬ Nrwl Community Slack
πŸ“Ή Nrwl Youtube Channel
πŸ₯š Free Egghead course
🧐 Need help with Angular, React, Monorepos, Lerna or Nx? Talk to us πŸ˜ƒ
πŸ›  monorepo.tools

Also, if you liked this, click the ❀️ and make sure to follow Juri and Nx on Twitter for more!

#nx

Some of the latest announcements:

Top comments (10)

Collapse
 
bradtaniguchi profile image
Brad

I got into nx a few years back and loved the idea for my Angular repos.

Today I'm using React and still using nx.

I'm currently looking into nextjs, and still probably going to use nx! XD

Collapse
 
juristr profile image
Juri Strumpflohner

πŸ™ŒπŸ˜„

Collapse
 
raduable profile image
raduable

I kept wanting to switch to monorepos, but never found the proper time.
I think now with all this tooling that Nx provides, and other solutions as well like Turborepo, it would be a good time to make the switch.
Just have to decide which one to adopt - do you have any experience with other tools besides Nx?

Collapse
 
juristr profile image
Juri Strumpflohner • Edited

Best is to go to monorepo.tools which has a list of tools and their features.

Collapse
 
andrewbaisden profile image
Andrew Baisden

Very interesting.

Collapse
 
eshimischi profile image
eshimischi

Chose Turbo instead but had experience with nx and my Vue projects before

Collapse
 
get_infinite profile image
Infinite Table

@eshimischi How would you compare the two?

Collapse
 
eshimischi profile image
eshimischi

Turbo is lighter, very fast integrating process, no complaints

Thread Thread
 
juristr profile image
Juri Strumpflohner

Nx has two different approaches to monorepos: one using plugins which is usually providing better DX in the long run, but is certainly more involved initially.

The second approach with Nx is the same Lerna originally took (and now also Turbo) which is with local node_modules, separate package.json per package etc. Easier to get started and ideal for incremental adoption, but usually harder to maintain in the long run.
Check out the 1st video I embedded in the post. That shows a setup that is identical if not easier than Turbo, but has some more options in the long-run πŸ˜ƒ

But in the end, choose what works best πŸ˜ƒ

Thread Thread
 
eshimischi profile image
eshimischi • Edited

Instead of Lerna, chose Pnpm workspaces long ago (So Turbo + Pnpm workspaces work for me)