Other JavaScript frameworks
Express is a robust solution that has been around for more than 10 years. It is a great choice for building APIs, especially REST APIs. However, the JavaScript ecosystem is constantly evolving. Following Express, many JavaScript frameworks have been created to provide a more comprehensive and powerful set of features. Some of these frameworks, such as NestJS, integrate Express to expose similar routing and middleware capabilities. Others, such as Koa and Fastify, are considered to be only “inspired” by Express, providing more performant and developer-friendly solutions than the latter. Let's take a closer look at each of these frameworks.
Koa
Koa is a lightweight Node.js framework. It is built by the original team behind Express. The main difference between Koa and Express is the way both frameworks implement middleware. Koa doesn't have a built-in middleware mechanism but relies on promises and async functions for controlling the program flow. This allows you to stop relying on callbacks and thus, helps you escape the so-called “callback hell.”
Another difference is that Koa doesn't provide routing out of the box. Instead, you can use third-party Node modules such as koa-router or koa-route to implement routing.
Fastify
Fastify is a general-purpose server framework for Node that shines with its highly-optimized HTTP APIs. The framework aims to be as fast as possible and the benchmarks comparing it to other Node frameworks back up that claim.
Additionally, Fastify provides an extensible plugin architecture and a growing ecosystem of plugins. The architecture is designed to ensure plugin independence and encapsulation. This eliminates a myriad of issues caused by cross dependencies and allows you to refactor your code without worrying about breaking other parts of the application.
NestJS
NestJS (sometimes referred to as Nest) is a framework that provides an additional level of abstraction above frameworks like Express and Fastify. It comes with an out-of-the-box application architecture that helps you iterate and scale fast. The architecture of NestJS is heavily inspired by Angular. Similar to Angular, NestJS is built from the ground up with TypeScript and NestJS applications are written in TypeScript.
NestJS uses Express for providing HTTP capabilities. However, it's easy to replace Express with another framework such Fastify, taking advantage of the better performance of the latter.
As mentioned above, NestJS comes with a lot of built-in architecture solutions, including a solution for database communication. NestJS provides integration with Sequelize and TypeORM, which can be used to connect to a SQL or non-relational database, such as MongoDB. There's also a Mongoose integration supported by the NestJS team. However, NestJS is flexible enough and you can also connect to your database by loading its native Node.js driver.