Skip to main content

Nestjs & Angular

NestJs is currently a popular server-side framework from Node. It is a useful tool to build secure and high performance enterprise-level applications. NestJs built on top of Express and Fastify is influenced by Angular (front-end framework) and OOP (Object-Oriented Programming). 

With NestJs, you can build applications in any size with scalability with TypeScript and JavaScript. Your large applications can be divided in to different modules. Each module may have its own controllersproviders and services

A Controller manages requests and responses. The route system maps the controller to specific request actions. The Controller frequently has more than one route. 

A provider can be a service, factory, or helper class that can be injected as dependency so you create various relationships of different parts of your applications. Commonly we used providers to manage user authentication and authorization  and data sources from Mysql, PostgreSQL, MongoDB, etc.

In this tutorial, you will learn to build a simple full stack web app using NestJs for back-end APIs and Angular for front-end. The app authenticates a user using register and login forms with JWT. It secures the user password using hashing function from bcrypt. An authenticated user is allowed to perform various tasks against Mysql database such as view and add new products, update, and delete products from the data source based on user roles (e.g. user, admin).



To get start with NestJs, you have to install necessary tools like Node, Visual Studio Code, and Mysql Server or XAMPP.

Comments

Popular posts from this blog

Filter and count rows in Nestjs & MYSQL database

In the earlier tutorial, you learnt to connect NestJs app with MYSQL database and do migration to add new column to the product table. Now we move on creating APIs to filter data by name with counting the number of products, by id, and delete a specific product from the database.  Execute the following commands to create products module, controller, and service in products folder: npx nest g module products npx nest g controller products npx nest g service products Update products/products.module.ts file to specify the products repository used in the current scope using forFeature method.  import { TypeOrmModule } from '@nestjs/typeorm' ; import { Product } from 'src/entities/product.entity' ; import { ProductsController } from './products.controller' ; import { ProductsService } from './product.service' ; @ Module ({   imports: [ TypeOrmModule . forFeature ([ Product ])],   controllers: [ ProductsController ],   providers: [ ProductServi...

Authentication & Role-Based Access Control Using Passport & JWT in NestJs MYSQL

In the earlier tutorials, you learnt to create API endpoints to access MYSQL database and upload files in NestJs. In a real world application, it is common to protect API endpoints by restricting the APIs and grant permissions to only authenticated users.  From a client app, a visitor can register a new account using username, email, password. The default role of the visitor is user. The password is encrypted using bcrypt package. Then after successful registration, he/she can login using username and password. Upon successful login, a valid JWT (JSON Web Token) will be generated and returned to the client. To get permission to access subsequent API endpoints, the client has to send the token in headers to be validated on server. The very popular package to do authentication in NestJs is Passport. In the nestjs app, execute the following commands to install dependencies: npm install --save @nestjs/passport passport passport-local npm install --save-dev @types/passport-local npm ins...