fbpx

CYBRNODE

Crud Operations in NestJs (create, get, delete, and update)

Crud Operations in NestJs (create, get, delete, and update)

NestJS:

Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with and fully supports TypeScript.

Installations NestJS:

Before you can use NestJS to create your back-end application we need to make sure that the Nest CLI (Command Line Interface) is installed on your system. This can be done by using the Node.js Package Manager NPM in the following way:

npm i -g @nestjs/cli

Creation of new Project:

For creation of new project in NestJs, Open terminal and type the following command.

nest new project-name

After creation project, create a course component with the following command.

ng g c course

Creation of new Project:
For creation of new project in NestJs, Open terminal and type the following command.

nest new project-name
After creation project, create a course component with the following command.

ng g c course

Crud Operations in NestJS:
In this Crud operation we are going to store, fetch, delete and update a Course entity. For database we are using MogoDb.

MongoDB(Mongoose):
Mongoose is a connector for MongoDb. It is the most popular MongoDB object modeling tool.

Start by installing the required dependencies

$ npm install --save @nestjs/mongoose mongoose

Course Entity:
First of all we are going to create course entity. It will define the blue print of course, like what are the properties of course.

course.entity.ts file:
Modules:
A module is a class annotated with a @Module() decorator. The @Module() decorator provides metadata that Nest makes use of to organize the application structure.

course.module.ts file:
Controllers:
Controllers control http request. It define the way of how the server will response according to a specific http request. Controller invoke the service that are define in service file.

course.controller.ts file
Services:
Services are the functionality of a product(software). It consist of all the functions, that are going to be invoke by controller.

course.service.ts file
LOGO

Thanks for Submit

We have received your request. Our team will get back to you shortly