Senecajs Vs Nestjs

Posted on  by admin

I recently got into microservices, and I discovered API Gateway pattern that seems to be suitable for pretty much all kinds of situation.

As a way to learn this pattern, I created a nodejs project using nestjs framework. What I am trying to implement is simple. Simple blog platform website where user can view blog posts and create a blog post when signed in. Below is step-by-step procedures:. Build API Gateway as single access point for client. When client makes request to service that requires authentication, API gateway, instead of sending user to the service, will redirect user to first authenticate through my authentication service. Once authentication service verifies the user, it will send 200 response to the API-Gateway with jwt attached to the user cookie. Gateway will see the user is authenticated and directs the client to the Post service.

What I am wondering, though, is how to build this API gateway in the first place.

Should I build API Gateway in nestjs?

  • What would be suitable choice in general? In case I am building a gateway other than nestjs, how would I be able to make them work together?
  • I can see my questions being too generic, but I'm basically looking for guideline in building such service.
  • I am a big fan of NodeJS for its thin simplistic approach. I have been using Node.js since 2011–12 and Express has been my default framework of choice for quick prototyping or writing micro-service API.

Over time I have played with some other Node.js frameworks like sails, koa, loopback, etc.

  • Somehow end of the day I always had to come back to Express.
  • But from late 2018, I have been using NestJS and kind of feeling like: at last, I have found the right framework I have been looking for this long time.
  • This post is about self-reasoning why I am choosing Nest over Express or other frameworks.

Express is an un-opinionated, minimalistic framework. Un-Opinionated frameworks highly trust the developers to make the right choice. It allows developers to choose whatever tools or technologies, middleware, hooks they want to use.

Developers structure their codes without any specific structure that is forced by the framework. Express being an un-opinionated framework does not come with any specific template engine, body-parser, error handler, etc.

This is kind of good for a geek developer. I used to love this freedom. Every time I had to scaffold a new project, I used to decorate it with the tools of my own choice. But making a choice for a team is always difficult. If you have two other developers in your team, one might love ejs, the other might love blade as the template engine.