Skip to main content

Posts

Showing posts with the label NestJS-Technology

Part-5 | NestJS(v9) | Angular(v14) | MongoDB | CRUD Example

The main objectives of this article are: Create HTTP Post Endpoint In NestJS Application. Angular Application Add A Form To Create New Item. Create HTTP Post Endpoint In NestJS Application: In our service file implement the logic to save a new document to the MongoDB. NestJS_App/src/super-heroes/super-heroes.service.ts: async create(superHeroes: SuperHeroes) { const newSuperHeroes = new this.superHeroModel(superHeroes); return await newSuperHeroes.save(); } Here our payload 'superHeroes' is converted to the MongoDB collection model document type and then invoking the 'save()' method that saves our new document into the MongoDB. Let's add the HTTP Post method to our controller. NestJS_App/src/super-heroes/super-heroes.controller.cs: import { Body, Controller, Get, Post } from '@nestjs/common'; import { SuperHeroes } from './schema/super-heroes.schema'; import { SuperHeroesService } from './super-heroes.service'; @Controller('su

Part-4 | NestJS(v9) | Angular(v14) | MongoDB | CRUD Example

The main objectives of this article are: Create HTTP GET endpoint  in nestjs application Consume GET API and render the response in angular component Create HTTP Get Endpoint In NestJS Application: In 'SuperHeroesService' implement logic to fetch the data from the MongoDB NestJS_App/src/super-heroes/super-heroes.service.ts: import { Injectable } from '@nestjs/common'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; import { SuperHeroes, SuperHeroesDocument } from './schema/super-heroes.schema'; @Injectable() export class SuperHeroesService { constructor( @InjectModel(SuperHeroes.name) private superHeroModel: Model<SuperHeroesDocument>, ) {} async getAll():Promise<SuperHeroes[]>{ return await this.superHeroModel.find().exec(); } } (12-14) The 'find()' method fetches all documents from the MongoDB collection. Let's create the 'SuperHereosController' in the '

Part-3 | NestJS(v9) | Angular(v14) | MongoDB | CRUD Example

The main objectives of this article are: MongoDB MongoDB Atlas Cloud Service MongoDB ConnectionString Install Mongo Libraries In NestJS App Create A 'SuperHeroes' Module In NestJS App Create A Service Like 'SuperHeroesService' In NestJS App MongoDB: MongoDB is a document-oriented database, which is classified as a NoSQL database. In MongoDB, tables are called collections, and records are called documents. It stores data in BSON format. The BSON is binary serialization of JSON. The reading of data from MongoDB is faster when compared to the Relational Database. But MongoDB doesn't have a relation between the collections. We can't declare NoSQL is better than SQL or vice-versa. So depending on the application requirement either select NoSQL or SQL or Both databases. MongoDB Atlas Cloud Service: For our demo of using MongoDB let's use the MongoDB Atlas cloud service. (Step 1)So let's go to the MongoDB Atlas website and then signup for 'Free'(pricin

Part-2| NestJS(v9) | Angular(v14) | MongoDB | CRUD Example

The main objectives of this article are: Angular Creating An Angular 14 Application Install Bootstrap Package Add The Bootstrap Menu Angular: Angular is a component-based application. The angular component comprises 3 files like Typescript File(*.ts), HTML File(*.html), CSS File(*.css). Components typescript file and HTML file support 2-way binding which means data transfer takes is bi-directional. Component typescript file listens for all HTML elements events from the HTML file. Create An Angular(v14) Application: To create angular applications, first, we must have Angular CLI in our local machine. Run the following command to install the Angular CLI npm install -g @angular/cli Run the following command to create the angular application ng new name-of-your-project While creating an app to add routing say 'yes'. Select 'CSS' style sheets as default Let's get familiar with default files in our angular project :- package.json -  contains commands like build,

Part-1| NestJS(v9) | Angular(v14) | MongoDB | CRUD Example

The main objectives of this article are: NestJS And Angular Application Communication NestJS Create A NestJS Application Debug NestJS Application From Visual Studio Code Editor NestJS And Angular Application Communication: User request the Angular application(single page application) then js files are downloaded and then runs the application on the browser. Since Angular is a single-page application it depends on API for data to display. So Angular requests the NestJS endpoint through HTTP requests. NestJS API that runs at the server gives the JSON response. NestJS API communicates with the database for fetching and storing the data. NestJS: NestJS is a framework used to develop the server-side application. NestJS is built on top of the Node.js framework just like Express. It is the combination of Progressive Javascript, Object-Oriented Programming, Functional Programming, and Functional Reactive Programming. NestJS application built with 'Models' and 'Controllers' to

A CRUD Operation Demo On NestJS Using Azure Cosmos DB

In this article, we are going to implement  CRUD operations into the NestJS application using Azure Cosmos DB. Azure Cosmos DB: Azure Cosmos DB is a fully managed NoSQL database. NoSQL says data will be stored as a key/value JSON document. Cosmos DB provides 'High Availability' and 'Low Latency' for any application. Cosmos DB is very quick in response delivering, auto-scaling, effective auto failure management, etc. Any existing application that works on different DBs can be easily migrated to Azure CosmosDB as it provides APIs for integration like 'SQL/Core API'(most recommended API, our demo uses this 'SQL/Core API'), 'MongoDB API', 'Cassandra API', 'Germlin API', 'Table API'. Let's understand the structure of the Cosmos DB: Create an Azure Cosmos Account with an appropriate subscription inside of the Azure portal. After creating the Cosmos Account, we can manage the data of our account by creating 'Database'