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.

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;
}
 

Eigentlich gehe ich die Anleitungen Node.js MongoDB Driver und MongoDB 2.0.0 Driver durch.

Folgende zwei Befehle installieren Node.js Treiber für MongoDB und das Mongoose ODM (Englisch: Object Data Mapping)

npm install mongodb
npm install mongoose
 
mkdir project1
cd project1
npm init

vi package.json
 

Abhängigkeit zu MongoDB angeben:

  "dependencies": {
    "mongodb": "~2.0"
  },
 

Angepasste package.json sichern und nun die Abhängigkeit installieren:

npm install
 

Nun eine Test-Verbindung zu MongoDB aufbauen:

vim app.js
 
var MongoClient = require('mongodb').MongoClient
var assert = require('assert');

var url = 'mongodb://localhost:27017/test';

MongoClient.connect(url, function(err, db) {
    assert.equal(null, err);
    console.log("Mit dem Server verbunden.");
    db.close();
}); 

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