Authentication with Passport JWT

This is the third part of Getting Started with NestJS. This document was updated to use NestJS 5.3.6

We use Passport as our authentication middleware with NestJS. It suppport different methods, in Passport it’s called Strategy, to authenticate e.g Local, OpenID, Facebook, Google Account and Twitter. We use the local one.

We need a user entity to persist registered user. This is the same task as creating the product entity from last time.

Create folder user in folder nestjs-backend/src.

Create file user.entity.ts in folder nestjs-backend/src/user.
Continue reading “Authentication with Passport JWT”

Add TypeORM to NestJS Project

This is the second part of Getting Started with NestJS. This document was updated to use NestJS 5.3.6

We add sqlite3 database support with TypeORM. Install TypeORM and sqlite3 for our project:

npm i -s @nestjs/typeorm typeorm sqlite3

In folder nestjs-backend/src create folder product.

In folder nestjs-backend/src/product create the file product.entity.ts.


import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';

@Entity()
export class Product {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 500 })
  name: string;

  @Column('text')
  description: string;
}

Continue reading “Add TypeORM to NestJS Project”

Getting Started with NestJS

We are getting started with NestJS. This document is a work in progress and it gets updated as we go. This document was updated to use NestJS 5.3.6 We use Visual Studio Code, download and install it. Open the console in VS Code with View|Integrated Terminal. Now create a new folder for the project on the console and open it as VS Code project folder:

 mkdir nestjs-backend code -r nestjs-backend

Install Node.js if you don’t have it yet. Check for npm version (currently 5.6.0), npm comes with Node.js.

npm -v

If the version is older than 5 update it with

npm install -g npm

Continue reading “Getting Started with NestJS”

Handle offline and online status

Check if your web app is offline/online and show the status and handle it when the user triggers something needing the connection. [Mozilla: Online and offline events](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/Online_and_offline_events)