天天看點

視訊網站 + APP + 小程式, 技術:NodeJs (nestjs)+ VueJs全棧(1)

基于nestjs搭建的伺服器端

1.環境配置

最好使用最近最穩定的node版本,因為nest使用了ts語言,舊版本的node可能會不支援某些語言,

例如,低于10.15的node會報錯。

logSettings_1.logger.warn('You are using a NodeJS Version below 10.15.0, Please Upgrade!');
ReferenceError: logSettings_1 is not defined
           

如何更新node版本?

(1)mac os,Linux使用者使用n子產品更新,在指令行中輸入:

npm i -g n
n stable(或者其他您想要更新的版本)
node -v 檢視版本更新成功
           

(2)Windows使用者

無法支援更新使用的n子產品,老老實實覆寫環境變量的node安裝路徑,具體檢視,裡面有詳細的說明。

https://blog.csdn.net/busybm/article/details/80545912

2.引入對應的資源

npm或者yarn安裝nest,并且啟動nest項目

我們使用npm,以下四步是nestjs主要搭建伺服器端:

pnpm add -g @nestjs/cli
           

nest建立新項目

在項目中添加app,子目錄為admin

nest g app admin
           

watch模式監聽admin的變化,如nodemon子產品

nest start -w admin
           

以下三步是MongoDB和typegoose主要搭建伺服器端:

主要引入MongoDB子產品,和基于typescript的mongoose子產品

nest g lib db 

pnpm add nestjs-typegoose @typegoose/typegoose
// Mongoose publishes its own types, so you do not need to install this package.
pnpm add mongoose
           

資料庫

上文的nest g lib db ,生成一個目錄去管理資料庫端,我們這邊采用一個資料庫對應admin背景和apps前台

最後,可以在db的子產品中,添加其他表

繼續閱讀