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

Viewed 2682

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.

3 Answers

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.

Contrary to popular opinion, I'll suggest to get to know express a bit, make a plain simple server with JS and express (no fancy framweorks), convert it to TS. Get to know express library and how it works. NestJS abstracts a lot of the express'y' stuff. Its always good to know how it works under the hood.

I came from plain old JS + express to NestJS, and it feels good to know how it works under the hood.

It need not be a big app, just create a TODO with Auth,Validation and DB.

There is nothing wrong starting with NestJS though.

In my opinion, You should go for nestjs. Typescript is the future. Once you are into typescript, you will love using it. Nestjs gives a very clean structure for building web apps. It can be compared to well established frameworks like LARAVEL, DJANGO in case of functionalities. yes it may not be as popular but it is growing. I really recommend using nestjs. The upside is, you don't always need Typescript for it. Nest can work fine with plain javascript as well.

Related