Skip to main content


Showing posts with the label PostgreSQL

NestJS JWT Auth Cookie Series - Part-1 - User Registration

This is the first installment of the NetsJS JWT Auth Cookie Series. In this part our main focus on user registration by the NestJS endpoint. PostgreSQL Database: For this demo, I'm using the free open-source PostgreSQL database. Here I'm going to use the PostgreSQL docker image because it is easy and fast to set up and configure.  Click here to getting started with PostgreSQL docker . Run the following database query to create the 'User' table. CREATE TABLE User( UserId SERIAL PRIMARY KEY NOT NULL, FirstName VARCHAR(200) NULL, LastName VARCHAR(200) NULL, Email VARCHAR(200) NOT NULL, Password VARCHAR(200) NOT NULL, RefreshToken VARCHAR(1000) NULL, RefreshTokenExp DATE NULL ) Create A NestJS App: Let's begin our demo by creating a sample NestJS application. Command To Install NestJS CLI npm i -g @nestjs/cli Command To Create App nest new your_project_name Install ORM And PostgreSQL NPM Packages: ORM packages are essential to install because they prov

Introduction On PostgreSQL Database Using Docker

PostgreSQL is a free open-source relational database management system. In this article, we will learn basic steps to run the PostgreSQL Docker image. Install And Setup Docker: Step1: Download docker into our local system "" . Docker was available for all desktop operating systems. Step2: After downloading the docker installer, then install it. Now to run any docker containers(eg: Redis, MongoDB, PostgreSQL, etc) this docker instance we just installed should be active(should be running). Postgres Docker Image: We have to download or pull the Postgres docker image into our local system by running the below command. docker pull postgres Run Postgres Docker Container: After downloading the Postgres image, need to start the container by running the below command. docker run --name mypostgres -e POSTGRES_PASSWORD=secret -p 5432:5432 -d postgres --name flag to specify the name of our container. -e flag to specify an environmental variabl

Part-1 NestJS JWT(Json Web Token) Authentication(Access Token Implementation)

In this article, we are going to explore the implementation steps of JWT(JSON Web Token) authentication in the NestJS application. In this process of authentication, we going to use the 'passport' library(nodejs library) where we write simple customizable authentication. Create A Sample NestJS Application: Let's understand step by step implementation authentication in NestJs application, so let's begin our journey by creating a sample application. Command To Install CLI: npm i -g @nestjs/cli Command To Create NestJS App: nest new your_project_name Create Users Model: Create a 'User' model that represents the table. For now, let's create a simple class in the upcoming steps we make it compatible to communicate with the database. src/users/users.ts: export class User{ id:number; userName: string; password: string; } Create A UsersService: The 'UsersService' is a logical container for our 'Users' data. For now, just mock the user&

NestJS API CRUD Operation Using PostgreSQL Relational Database

NestJS API is a server-side framework that runs on NodeJS frameworks like Express. NestJS application has the ability to talk with both SQL and Non-SQL databases. Here we will develop a sample NestJS API application that communicates with the PostgreSQL relational database. NestJS Database Communication Flow: The 'pg'(PostgreSQL NodeJS library) library was used for communicating with the PostgreSQL database. The 'typeorm'(NodeJS library) library is a framework used for querying the database or manipulating the database using the specified database library(in our case 'pg' node library). The 'typeorm' will be used for all database configurations also. The '@nestjs/typeorm'(NestJS ORM library) is an overlay or wrapper for the 'typeorm'(NodeJS library). By using '@nestjs/typeorm' it gives the advantage of Typescript compatibility and additional feature over 'typeorm'(NodeJS library). So while implementing NestJS application

Steps To Setup PostgreSQL Database Using ElephantSql Cloud Service

PostgreSQL is made of an object-relational database management system. PostgreSQL is a free and opensource relational database. PostgreSQL database supports all features of the SQL database with more extended features. ElephantSQL is a hosting cloud service for the PostgreSQL database. ElephantSQL will manage administrative tasks of PostgreSQL such as installation, upgrades to the latest stable version, and backup handling. For more information ElephantSQL check docs (""). ElephantSQL Create User Account: To consume the ElephantSQL cloud service let's create a user account for authentication. ElephantSQL Authentication Path: ElephantSQL provides multiple authentications like 'SAML Authentication', 'GitHub' and 'Google'. Use any of the login technique of your desire to create an account. Accept Agreements: After successful login, ElephantSQL shows 'Terms of S