DahisC / DahisC.github.io

Github Page 部落格,以 Hexo 架設
0 stars 0 forks source link

Nest 筆記 #21

Open DahisC opened 2 years ago

DahisC commented 2 years ago

Controller

image

簡介

以路由(Routing)機制接收特定的請求,通常一個 Controller 都會擁有複數的路由

快速建立

單一 Controller

$ nest g controller [name]

CRUD 路由

$ nest g resource [name]

實作

@Controller(路由前綴)

@Controller() 建立路由,並在括號內填入路由前綴(以簡單地群組化路由)


Provider

image

簡介

大多數基礎的 Nest 類別都可以當作 Provider,主要是為了讓 Provider 可以在需要時依賴注入(The main idea of a provider is that it can be injected as a dependency),不同的 Provider 之間可以相互繼承以擴展類別實例的功能

快速建立

Service

$ nest g service [name]


Module

image

簡介

Module 是建構整個應用程式的組合單位,可包含 Providers, Controllers

快速建立

$ nest g module cats