NestJS vs ExpressJS

How to choose the best framework for your next project

Kobbi Gal

Posted September 15, 2022

10 min read

Learn NestJs the right way

Skyrocket your NestJs skills to the top

with Vladimir Agaev
Full Stack Developer
  • checkNestJs Architecture
  • checkSessions
  • checkCaching
  • checkPagination
  • checkScaling with Redis
  • checkUnit Testing
  • checkRBAC & CronJobs

Introduction

When beginning a new NodeJS project, web developers are caught in an eternal dilemma: "which framework should I use to develop my API service"?

The two most popular and favoured choices are NestJS and ExpressJS.

In this article, we'll explore the key differences between the two frameworks and attempt to give developers an encompassing picture that will help to decide which framework is suitable for their project and needs.

Before we start, It's important to remember that NestJS is built on top of ExpressJs.

Which is More Popular/In Demand?

One of the most important considerations when choosing between the frameworks is their popularity. Popularity provides the developer or architect an understanding of how much support this framework is getting, how large of a community it has and which/how many libraries it has.

It will help the developer get answers to their questions when the framework is being widely-used, more robustness as the more supported the framework, the more development time is put into it to resolve bugs and unit tests. Lastly, the wider the audience using the library, the more likely the developer will not have to reinvent the wheel and will be able to use one of the provided libraries.

Raw Statistics

To understand which framework is more popular with the community, let's look at some dry statistics gathered from the 2021 State of JS survey. The survey included 16k developers from all over the world.

Let's look at the popularity changes over time. The graph shows how likely the developers will use the framework again or recommend it to their peers.

We can see that ExpressJS has constantly been in the upper-right quadrant, which means that it is used and reviewed extensively.

NestJS's line is a bit shorter because it is a relatively new framework. So we have fewer data points. However, we can see that NestJs had a significant leap in popularity between 2018 and 2019 and has seen a slight increase in usage but also falling popularity. Here's another graph with a bit more resolution about the survey reviews:

ExpressJS:

NestJS:

The ExpressJS survey says that 58% of the developers would use it again, while 8% would never use it again. NestJS has 13% approval for repeated usage and 2% saying they would not bother using the framework in another project.

Open Source Contributions

Now that we have collected some raw data and community opinions let's look at how the open source repositories are doing in popularity.

A good indicator of the popularity of the repository would be opened/closed issues and Pull Requests since 2020 (normalized to when NestJS was released), as well as the code frequency, number of stars and forks. Here's a table summarizing the statistics gathered from the frameworks GitHub page:

Stars (k) Forks (k) Watchers (k) PRs Merged (2020 - 2022) Issues (2020-2022) Used By (m) Contributors
NestJS 50.6 5.9 693 2,323 1,833 0.18 332
ExpressJS 58.3 9.9 1.7 37 431 15.9 284

We can learn a few insights from this table:

  • Express was released 12 years ago! Going by the time NestJS has been out in the wild, it has closed the number of stars and forks gap. NestJS has been out for two years only but has only 14% fewer stars and 40% of Express's forks.

  • The number of merged PRs easily tilts towards NestJS in the last two years

If we look at the code frequency (additions/deletions per year), we can see clearly that in the last two years, NestJS has seen a lot more activity:

ExpressJS:

NestJS:

This discrepancy can account for number of contributions/popularity of the framework but also can be explained by the differences in maturity between the two. Since Express has been out there for a very long time and not updated as much, it likely requires less maintenance so fewer PRs and issues are open as a result.

  • NestJS has more contributors than ExpressJS, even though it has been out for ten years! This means that there are more people actively working to stabilize, fix and add new features or documentation to NestJS.

  • ExpressJS has 100x more public references to the package found in GitHub projects than NestJS. This is not surprising since Express has ten years advantage over NestJS. Ironically, NestJS (which is built upon ExpressJS) is one of the almost 16 million projects that refer to ExpressJS.

Monthly Downloads

Another critical factor to consider with popularity is the download rates of the two frameworks.

Based on NPM, ExpressJS has had 15 million downloads in the last month while NestJS hit 6 million. Remember that ExpressJS is a dependency of NestJS so every one of the 6 million NestJS downloads also counts towards ExpressJS since it'll get installed with npm when NestJS Core is installed.

NestJS downloads also count towards ExpressJS since it'll get installed with npm when NestJS Core is installed. Given this, we have a 9 million downloads difference between Express and Nest, which is quite a lot. One of the many other explanations for this could be the fact that Express is seen as the more flexible, lightweight solution for small applications and use cases.

This would be the preferred choice for small-time hobbyists, start-ups and people looking to learn about web development from the ground up. All the while, the likes of enterprise-tier companies, which tend to use highly-opinionated and well-tested systems, to use Express is lower. There are many more former cases than the latter; hence we see more ExpressJS monthly downloads.

Employment

Since we're living in an economy which requires us to work for a living, we cannot ignore the employment factor. Developers looking to move positions or step up their game need to know that their chosen framework will make them hireable. Therefore, we also reviewed how many jobs are in the market and which framework they require.

According to data gathered from LinkedIn, Indeed and Upwork, ExpressJS has around 6k job openings, while recruiters only posted around 1k for NestJS. So learning Express means you're likely to be more employable right now. Still, as we can see in the sections above, it's closing the popularity gap with ExpressJS pretty quickly and might overtake Express as the more employable NodeJS framework at some point in the near future.

This is especially true since corporations are moving towards more opinionated, stable, and well-tested frameworks. Smaller companies or individuals who need to write and deploy their services faster will usually prefer to work with Express as it's more flexible and light. Now that we've crunched the numbers around framework popularity, we can review the part that might be most interesting for developers: the head-to-head technical comparison between the two frameworks.

Technical Comparison

Below we can see a summary of the technical differences between the NestJS and ExpressJS:

NestJS ExpressJS
Flexibility Focuses on conventions/principles Doesn't have predefined rules
Architecture

Follows MVC design pattern providing ready-to-use components

Has no built-in structure.
TypeScript

Supports TypeScript which is more reliable and universally supported.

No support. May not be supported on all browsers.

Efficiency

Includes CLI, Dependency Injection and 3rd-party plugins

Is asynchronous, not scalable
Popularity

2nd among top NodeJS frameworks on GitHub. Used by Adidas, Decathlon, Autodesk

Older framework so has large user base. Used by Netflix, IBM, eBay, Uber.

Testing

CLI includes default testing environment with jest and auto-generated unit tests.

Need to write unit tests manually
Use Cases Better-suited for enterprise-grade.

Better-suited for building fintech and streaming applications

Reading through the table, we can that the characteristics of each framework really give us an idea about what type of projects and users we would likely see use each.

When to choose ExpressJS

ExpressJs provides us with a 'quick-and-dirty' way to start a project from scratch when we don't have much time to sit and design a scalable, performance-driven application.

Choosing ExpressJs will give us more flexibility and we would likely hit the ground running faster by doing so. However, this will likely have drawbacks when and if the project becomes popular, more requirements or features will get added and it hog more system resources as a result.

vWe'd likely need to invest a very large amount of engineering time in writing unit tests and rethinking the architecture. Here are some additional reasons you'd choose ExpressJS over NestJS:

  • One of the biggest strengths of Express is its strong community and the number of available plugins.
  • Another big advantage of Express is that it is supported with the Google V8 engine, which ensures high performance without lags or errors in the processing

When to choose NestJS

On the other hand, development and design is very much abstracted away from the software architect in NestJS and is mostly focused on the Model-View-Controller (MVC) design pattern.

So to really get the most out of NestJS, the software developers/architects need to be fluent in MVC. Choosing NestJS will provide you with a stable, well-tested and scalable architecture. This is why it makes a great choice for large corporations and highly-available services.

Below are some other reasons that you would favour NestJS:

  • NestJS is entirely written in TypeScript, which is not the case with ExpressJS making ExpressJS less efficient and not also compatible with running on multiple browsers.
  • TypeScript has decorators that provide new ways to write APIs to modify how our code works at runtime.
  • Dependency Injection is also why developers choose NestJS since it allows you to add as many dependencies as possible for smooth application functioning. It provides a way to separate the creation of an object from its usage. By doing that, you can replace a dependency without changing any code, and it also reduces the boilerplate code in your business logic.
  • 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 the wheel. There really aren't so many options for web development technology that are a good enough reason to use Express over NestJS. For example, almost all web apps will need a way to store data (NestJS Providers) and handle requests (NestJS Controllers).

How to choose between ExpressJs and NestJs

Now that we have gathered and read through both frameworks' technical and popularity aspects, we can summarize how you should decide which NodeJS framework is the right one for your next project.

If you're part of a small team or are just getting your hands dirty in the NodeJs world, ExpressJS is likely the better choice. Since ExpressJS does not require a specific structure, it is better to learn how to write a web server from scratch. It is also a better choice if you're sure that this application you plan to develop will stay small. Since it has a vast community and many plugins, you will easily find solutions to your problems.

If you're part of a larger team and have more experience in software design and architecture, NestJS is likely the better choice for your situation. Since it's opinionated, it adheres to the 5 SOLID Principles.

The project will result in a higher likelihood of detection of issues during development, more code coverage and more manageability. Being part of a larger team, we could deduce that there is more at stake if the service fails, so the project needs to be universally supported, stable and scalable. Since NestJS supports TypeScript, it makes the application more reliable and bug-free.

Remember that everything supported in ExpressJS, for example, Express functions, is also supported in NestJS, which makes switching from one framework to another easier when the project is still in its infancy. So when choosing a framework and then expanding the team/availability/functionality of the service, you can always switch from ExpressJS to NestJS if you catch the wave early enough.

Learn NestJs the right way

Skyrocket your NestJs skills to the top

with Vladimir Agaev
Full Stack Developer
  • checkNestJs Architecture
  • checkSessions
  • checkCaching
  • checkPagination
  • checkScaling with Redis
  • checkUnit Testing
  • checkRBAC & CronJobs