Member-only story
Stop Using Express.js For Web Servers, Consider NestJS Instead
Here’s why NestJS is a better alternative
If you Google how to build a web server in Node.js, most tutorials will recommend Express.js, and for good reason — it’s a flexible and straightforward tool for those who are new to Node.js, Javascript, HTTP servers, or all three. However, its popularity often leaves new developers with the misguided notion that Express is the superior way to build a server in Node.
In reality, it’s not a great choice, particularly for enterprise use.
These days — and especially in the Node.js world — there’s a mysterious preference for lightweight, unopinionated libraries over batteries-included frameworks. It’s not entirely clear why this is. It may feel nice to use minimalist frameworks that leave room for personal design choices, but what makes your design choices better than those of experienced software engineers who have experimented with countless different architectures? Likely nothing.
Unopinionated frameworks force developers to redesign a wheel that has already been designed.
That’s why highly effective software developers capitalize on existing tools that have been tried and tested in many different use cases and over many years.
So, what are some of the alternatives to Express?
There are libraries like Koa, Fastify, and hapi
. But these share only a minimalist, lightweight approach that Express takes — thereby offer little help in providing a more robust out-of-the-box architecture.
Enter NestJS
NestJS is a truly batteries-included framework. It’s a TypeScript-first library that uses class-based architecture for modular web server applications. It offers official support for tools like GraphQL and WebSockets, with first-rate documentation included. And its dependency injection architecture improves code organization, simplifies testing, and increases test coverage.
This all might remind you of Angular, and it should, because NestJS borrowed much of its design from Angular. If that scares you, it shouldn’t — but more on that later.