You definitely should be using NestJS for your Node apps

Adam K.
Adam K.
Jan 21 · 3 min read
Photo by Baher Khairy on Unsplash

I will start with a bold statement. Using NestJS is super cool.

The creators of it (author Kamil Myśliwiec and other open-source contributors) got inspired by other great frameworks.

They were smart enough to steal some of the best ideas floating around: Modules from Angular, Repositories, Services, Entity annotations from Spring etc.

Nest is an open source web framework which uses TypeScript.

Let’s dive in.

Nest’s bold logo

Why would I need it anyways…?

Well, this is easy. Because it helps you a lot!

Want to create a table for your database? Nothing easier.
Just create a JavaScript class and annotate/decorate it with @Entity(). Voila! Table created.

A table in a database now exists. No SQL involved!

Want to create a nice API so that your React app can access that you manage through your NestJS app?

Create a JavaScript class, decorate it with @Controller().

Now you can further annotate your functions within that class to respond to HTTP requests (@Get, @Post etc.).

The result of these functions are then sent back to the client (Frontend Web Page, Mobile App, Smart Fridge and whatnot).

What about Express?

Everyone who starts learning Node.js will be introduced to Express, a “minimalist web framework for Node”.

It is crucial to understand that Express and NestJS are not rivals.

Express offers us a way to expose endpoints and respond to HTTP requests. That’s nice, however Nest does much more than that.

By the way, Nest is based on Express.

What can Nest do? Amaze me!

  1. Interact with your database easily in an abstracted manner. You just create and annotate classes with decorators. This is called Object Relational Mapping (“ORM” might sound more familiar)
  2. Create service layer classes easily to handle the business logic of your application. Then, inject (read: “use”) these services in other services with the help of NestJS’ dependency injection
  3. Create so called “Controllers”, which can easily respond to HTTP requests. This is your main way to interact with the clients of your Nest app (React? Vue? Mobile app? Another service? Anything.)
  4. Secure the endpoints you create with Controllers. Nest makes it easy to guard the API of your app, so only (for example) logged in users can access them (be it basic auth., JWT etc.)
  5. Create microservices with Nest. Cool.
  6. Build a GraphQL interface easily
  7. Integrate message queues into your app (maybe you need to do some asynchronous data processing?)
  8. …and much more

Take a look here…

NestJS got the first place in the Backend Technologies Predictions section of State of JavaScript 2019. Neat.

Nest uses TypeScript, a statically typed superset of JavaScript.
This can be handy when dealing with large and complicated projects.

More and more developers are now using Nest as their preferred server-side JavaScript web framework, and the number of projects built in it are growing in number.

Certainly give it a try!

Where to go from here…

The official documentation of NestJS is really good.

I’ve also started writing a mini-series about Nest, check out the first part here: https://medium.com/javascript-in-plain-english/exploring-nestjs-installing-nestjs-and-getting-started-fb2e4f36b596.

Cheers.

JavaScript in Plain English

Learn the web's most important programming language.

Adam K.

Written by

Adam K.

Let’s not waste time. Let’s build creative projects.

JavaScript in Plain English

Learn the web's most important programming language.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade