Search code examples
node.jstypescriptexpresssails.jsnestjs

Is NestJs a right choice for a node.js beginner or should I do something with Express first?


I know Nest.js is on top of Express JS and can be on fastify, I have completed the express JS library project in the Mozilla (MDN) training site but for many reasons like the architecture of the app and discussions that I saw on web about problematic situations with express and modern JS like async-await, etc…

I searched for a more reliable choice: sails-js, nest and feathers came up, feathers were awesome but Nest.js had very good documentation and I avoided typescript for a while, but as for now it seems to be everywhere, and I hope with nest I could get to know it better and the practical use of it, at frontend I honestly could not find a good reason for using it besides it's a trend, except for angular 2 plus. Don't get me wrong angular is one of the reasons I hope to come around TS.

Short Version

So this is my current situation as a frontend developer (vue & svelte mostly) a few months in NodeJS atmosphere (express and hapi) my question is: should I stick to hapi & express or go with NestJs & alternatives like feathers and sails?

Please forgive my lack of experience for writing in English.


Solution

  • Nest.js & Typescript is a framework for enterprise-level applications which provides a clear structure and guidelines of how things should be.

    So for the beginner pros are:

    • OOP (SOLID) in TS/JS
    • Introducing the latest LTS features of TS, like decorators, dependency injections, and so on.
    • In build ESLint, prettier, and monorepo mod which can be activated via Nest CLI.
    • Easy deployment via docker-compose for microservice architecture.

    You can't achieve these things via such old frameworks like Express + (something else)

    As for the cons:

    • It's hard to understand why there is a contoller file, service file, and why there are multiple module files with forRoot and forRootAsync connections to DBs and so on.

    • In time, it will be difficult to write/build projects w/o Nestjs because it's very good, but has a bit different pattern of programming.

    • @Afaq mentioned that TS is the future (and Nestjs as well), but it's a bit wrong. JS as a native language always inherits the best available options from TS, as it did with CoffeeScript and so on. So one day in the future, you could wake up and look at your TS codebase as a legacy without appropriate support, while native technology goes forward.