TypeScript has been steadily gaining adoption, and is in the top 3 most loved languages according to StackOverflow's 2019 Developer Survery.
Despite the growing popularity, there are fewer mature framework choices than pure Node (see my tour of Node.js frameworks).
A few major frameworks like Loopback@4, Feathers, and Adonis are all doing major rewrites from Node to TypeScript. These frameworks intend to interoperate with Node.js so users of the frameworks do not have to use TypeScript if they prefer Node.
Nest.js
Inspired by Angular's module system, Nest is by far the most popular TypeScript framework in 2020.
It has been growing steadily since being introduced in 2018, matching Koa's trajectory of adoption in the Node world:
Nest has actually outpaced most Node frameworks besides Koa and Express at this point in terms of downloads per week (to be fair, it was introduced multiple years later as well).
The central features of Nest are it's dependency injection mechanism, module system, and extensive use of decorators. In fact, decorators are used to declare modules and dependencies.
Here's a standard module declaration:
import { Module } from '@nestjs/common';
import { CatsController } from './cats.controller';
import { CatsService } from './cats.service';
@Module({
controllers: [CatsController],
providers: [CatsService],
})
export class CatsModule {}
A controller makes similar use of decorators:
import { Controller, Get, Req } from '@nestjs/common';
import { Request } from 'express';
@Controller('cats')
export class CatsController {
@Get()
findAll(@Req() request: Request): string {
return 'This action returns all cats';
}
}
I find the ability to use decorators to change parameters in controller methods both powerful and elegant. It's more expressive, declarative, and flexible than a context
object that holds every possible reference for the request/response.
Modules provide a level of isolation for dependency resolution, and a module can choose which services can be exported or imported into the module.
Nest provides a number of sharp tools, but does not provide a lot of opinions what you do with them - so it supports all sorts of configurations from monolithic MVC applications to event-based microservices:
- middleware
- pipes for validation, among other things
- guards for access control
- exception filters for easily handling runtime exceptions
- interceptors
- testing harness
It has official packages to integrate populate ORMs like TypeORM, queuing, logging, and others.
Foal
TBD.
TS.ed
TBD.
Honorable Mentions
Here are few frameworks that aren't production ready yet but deserve a place on this list.