NEST.JS for your NEXT PROJECT


Hi, I am Nandika Jeevantha. Currently, I am working as a trainee software Engineer in Virtusa (Pvt) Ltd. From years of experience in full-stack development I identified that NestJS is great stuff when you are about to develop backends.

Most in the past I used NodeJS with express for my backend development. But the main problem that I faced is not having a proper structure especially a folder structure in those technologies. when you are working in a large enterprise application this problem will bring headaches of course. Especially if you are an angular guy you will recognize of using the CLI greatly and great stuff of typescript. Nest is same as that. that’s why I really love this framework in building backends.

Here is the quote that I found in the NestJS documentation.

“Nest (NestJS) is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with and fully supports TypeScript (yet still enables developers to code in pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).”

And of course, it is “YES”. With no more explanations let’s forward

Let’s forward to the technical stuff.

First of all, you have to use nest CLI to start your project, run your project, and to do many things. You can easily install it using the following command in your cmd.

>npm i -g @nestjs/cli

After the installation you can start a new project using the following command.

nest new project-name

for the project-name you can use a name as you wish.

Ahh. I forgot something to mention. When creating a project, it prompts us which project manager would you like to use. Just choose npm.

Here is the folder structure of the brand-new project. I usually use WebStorm as my default IDE.



You might be familiar with nodemon. Every change that we do to the files nodemon starts again and again. Same as that we can start the NestJS project in watch mode. Simply use this command in your terminal.

npm run start: dev

or else you can use just npm run start

as a small discussion if we take a closer look at src/ directory several core files can be seen. Let’s talk about them one by one

app.controller.ts

here it is a basic controller sample with a single route

app.module.ts

this is the root module of the application

main.ts

this is the entry file of the application which uses the core function NestFactory to create a Nest application instance

well using nest.js is very easy and super cool.

Nest.JS returns

TypeScript Support: NestJS supports TypeScript, which makes me very comfortable as I have been using TypeScript for a long time while working with Angular. You have the option to select JavaScript again.

Code sharing: NestJS supports library creation and use using CLI. It’s really easy to share code and then it’s a good choice for business applications.

Monorepo support: Angular support monorepo, and starting at 6, NestJS comes with monorepo support.

How to learn: Another thing I love about NestJS when you come from .Net or a Java domain and have an idea for creating APIs, NestJS is easy to learn. Also, if you are an Angular developer, you will feel at home because it follows the same path.

Conclusion

NestJS is very easy to get started with, and once you have used .Net, Java, or ExpressJS, many concepts are the same.

It provides CLI, and with it, we use it, we can easily switch our app and focus more on our code. With a business application, it is really easy to split code into all multiple modules using NestJS modules.

This article is actually a basic forward step to Nest.I hope to continue with a detailed technical stuff as a continuation regarding to this.Connect with the future stories too about nest.

Stay Home.Stay Safe!!!!




Post a Comment

0 Comments