Skip to content

csulak/node

Repository files navigation

Node Project

Content:

About

Project based in nest, basic crud in order to learn about:

  • How to connect to DDBB SQL (MySQL -> typeorm)
  • No-SQL (Mongo -> mongoose)
  • HTTP Module (consume apis)
  • Mem Cache
  • Redis Cache
  • Login (JWT)
  • Endpoints with api-key
  • Swagger

Versions

Node Nest npm yarn Docker Docker Compose
16.2.0 7.6.0 7.12.0 1.22.10 20.10.6 1.29.1

Installation

$ npm install

MySQL branch(master)

HTTP calls made as Promise way

  • You need to check the configuration/credentials in ormconfig.json file

  • Make sure to have an MySQL instance running on the specified port (default 3306)

  • Generate an instance of Redis Cache running in the default Redis Port 6379

  • Create a DB with the name specified in the previous file named

  • Tip1: If you have a problems to read the entities, when you are starting the repo, or when you call some endpoint run: $ npm run build

  • Here you have a basic tutorial of how to install, run and create MySQL DB on Linux

Mongo branch

HTTP calls made as Observable way

  • Make sure to have an Mongo DB instance running on the specified port

  • Check the app.module.ts file, on import you can see MongooseModule and their specific configurations

  • Generate an instance of Redis Cache running in the default Redis Port 6379

  • Here you have a basic tutorial of how to install Mongo DB on linux

Running the app

# Step 0
$ npm i

# Step 0 bis
$ npm run build

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Swagger Endpoints

Swagger

Steps to create base project

# Install Nest Cli (Project generator of Nest)
$ npm i -g @nestjs/cli

# Creates Nest project
$ nest new 'project-name'

# Transpiles code to Js
$ npm run build

# Create a new controller named "task"
$ nest generate controller tasks

# Create a new Service named "task"
$ nest generate service tasks

# Create a new Module named "task"
$ nest generate module tasks

You can see in the root of the project are: app.module, app.service, app.controller. Those are the mains.

Util links

Official Nest js Documentation

From here I learnt to make PUT in mongo and throw 404 exception

Express Js beginner course

From here I learnt MySql TypeOrm

How To apply Swagger in your node project (basic)

How To apply Swagger in your node project (intermediate)

How to apply Cookies in nest official doc

Decode and Encode tokens here

JWT LOGIN HASH implemented as Observable way (I migrated this solution to Promise way)

About

Learning about node

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors