Getting started with Nest.js

This article marks the beginning of the Nest.js tutorial series. Like any other, we should first learn the basics. In this tutorial, we are going to get through the basic introduction to Next.js which will help you get started with any Next.js project in the future. Mind that the basic JavaScript knowledge is necessary in order to get started with this Nest.js programming tech.

What is NestJS..?

NestJS is a progressive JavaScript framework for building constructive, scalable, and efficient Node.js server-side applications. This framework supports
- TypeScript
- OOP (Object Oriented Programming)
- FP (Functional Programming)
- FRP (Functional Reactive Programming)

NestJS uses HTTP server frameworks like Express under the hood. It also allows us to configure Fastify.

NestJS offers a level of abstraction above these common Node.js frameworks (Express/Fastify), but also delivers their endpoint APIs directly to the developer. As a result, developers can freely use numerous third-party packages that supports this ecosystem.

Installing NestJS

We can install NestJS by two way:

Since, this is tutorial deals with a programming tech. We can assume that the one reading this article is already familiar with Git and its functionalities. So, cloning the started project can be easy.

Here, we are going to get the project started with Nest CLI instead.

For that, we need to install the Nest CLI using the Node Package Manager(NPM) first. To install the Nest CLI plugin globally we can run the following command in our terminal:

npm i -g @nestjs/cli

After the successful installation of Nest CLI, we can create the new NestJS project running the following command in the desired directory:

nest new project-name

This command handles everything to get us started with the starter NestJS project. All the required files and configurations are automatically generated as you can see in the screenshot below:

The project folder structure will look something like this:

We will talk about the project folder structure and files in the next chapter. For now, let us get a closer look at Nest CLI and know it better.

Nest CLI

Nest CLI is a command-line interface that helps us initialize the project. By using Nest CLI, we can generate the best-practice folder structure for the Nest project.

Example commands in Nest CLI:

nest --help // help list for cli
nest -h // alias for nest generate <schematic> <name> [options] // for create file
nest g <schematic> <name> [options]
  • <schematic> is something we need to build
  • [options] is optional command

The example use case is shown below:

nest g controller cats --no-spec// is command for create controller name cats without create test file 

The result of running the above command is shown in the screenshot below:

Here, the cats controller transcript files are automatically generated and imported in the main file.

If we select other schematic example modules:

nest g module cats --no-spec

We get the following result:

If you want to check the other use cases of Nest CLI, be sure to check out this Link.

In this chapter, we got a brief intro of NestJS, how it works, and what it supports. We learned how to create a new NestJS project using the Nest CLI. Then, we get some deep insight into what Nest CLI has to offer. In the next chapter, we will talk about the NestJS folder structure and files. We will get deep into the purpose of each file in the project structure.

Defi farmer at https://maticdaily.news , l❤Polygon, MATIC Holder