2 min read

Why I chose NestJS over Express for a system meant to outlive me

Rebuilding a logistics platform from scratch, I picked NestJS on Fastify over Express. Not for performance: for dependency injection that is enforced by default rather than left to discipline.

  • NestJS
  • Express
  • Fastify
  • Dependency injection
  • Architecture

When we decided to rebuild our logistics system from scratch, the obvious choice was Express. We knew it, it's fast, and it stays out of your way.

I picked NestJS. Not for performance — I took performance out of the equation entirely.

Nest isn't a server. It's an organisational layer that runs on top of Express or Fastify. So I ran it on Fastify, which closed the one argument that could have stopped me. That left the decision resting on something else: how the code reaches itself.

In the codebase I'd worked in before, every file that needed the repository instantiated its own copy.

The problem with that isn't memory — the instance is a handful of bytes. The real costs are elsewhere:

  • If each copy holds its own connection or cache, you lose pooling and state fragments.
  • Testing becomes close to impossible. When a class news up its own dependency, there's no seam to swap in a mock. You end up hitting the real database.
  • And any change to a constructor means touching dozens of files.

I first solved it by making the classes static. It fixed the duplication and introduced a different problem: the dependency was now fixed at write time. I couldn't swap it in tests, and I couldn't run two instances with different configuration.

And here's the part I should be straight about:

All of this was solvable in Express. Instantiate once and export it, or reach for a DI library like tsyringe or awilix. There is nothing here that only NestJS can do.

The difference is that Express leaves it as a choice, and Nest makes it the default path.

That's what mattered to me. On a small project with one developer, discipline is easy. On a system that will keep growing for years and get handed to engineers who've never seen it, discipline is the first thing to go when a deadline arrives.

So what I chose wasn't a capability. It was having that capability enforced rather than left to judgement.

Two years on, that system handles over 20M shipments a year.

Express wasn't the wrong choice. It was the wrong choice for a system meant to outlive whoever wrote it.

More writing