0 -ゼロからのネストJS



ペンダンスのインストール
機会を与えてください.
mkdir 0-nest-from-scratch
cd 0-nest-from-scratch
Dans国連公認Temps、イルfautイニシアザーNPM.
npm init
装飾のペンダンスについて
npm i -D @[email protected] @types/node
Pendanceのインストール
npm i @nestjs/core @nestjs/common @nestjs/platform-express reflect-metadata

設定のタイプスクリプト
La Friierを通してのConfigurer TypeScriptの上でtsconfig.json
{
  "include": ["src/**/*"], 
  "compilerOptions": {
    "module": "CommonJS",
    "target": "ES2017",
    "outDir": "dist",
    "experimentalDecorators": true
  }
}

CRモジュール
UNIXアプリケーションNESTJSは、開始は、UNIXモジュールを開始します.
の上のDoncは、r cr er fiferですsrc/app.module.ts .
アップリケのコーラスにおけるモジュールとしての機能@Module クィーヌウスヴィントデ@nestjs/common .
import { Module } from '@nestjs/common';

@Module({})
export class AppModule {}

制御に関する一考察
C ' est bien beau d ' aboir unモジュールmais faul ilアンコールen faire quelqueは選択しました.
Cela nous allons CRを注ぐ.
コンシューマーの輸出に関する一考察@Controller インポートドデ@nestjs/common .
import { Controller } from '@nestjs/common';

@Controller()
export class AppController {}
Le Moment , Notre Controlleur n ' est pas trθs utile
Nous Allons Donc Lui Ajouter une m ' s ToesayHello クェン・リターネラHello Nest .
import { Controller } from '@nestjs/common';

@Controller()
export class AppController {
  sayHello(): string {
    return 'Hello Nest';
  }
}
エヌMエドトム、C ' estビアン.uneルート、C ' est mieux!
トランス変圧器sayHello エヌRouteur HTTP、IL接辞デLuiアップリケルd@Get()
import { Controller, Get } from '@nestjs/common';

@Controller()
export class AppController {
  @Get()
  sayHello(): string {
    return 'Hello Nest';
  }
}
注ぐen finirのavec notreスーパーcontroleleur、ajoutonsルtout簡素化dansルモジュールque nousエイボンcr ces pr pr c c demes.
AjoutonsラクラスAppController セクションcontrollers DESオプションのNOTREモジュール.
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';

@Module({
  controllers: [AppController]
})
export class AppModule {}

<研究ノート>main.tsトップ!
Maintenant que nous avons unmoduleとun controlleur,il va nous falloir d . marrer notreアプリケーション
アルサーCE奇跡、Nous Allons CRmain.ts Qi va se充電器deコンパイラLEモジュールet lser le serveur
Appelleraのブートストラップに対するCR CR EE UNE FORINTION非同期式の開始
L ' Executeの上のetスイート.
async function bootstrap() {}
bootstrap();
Le Le Le Le eeur de la Fonction Bootstrap , CR Les on Un可変的なアプリケーションqui va recevoir le r so sultat de nestfactoryavec notre appmodule en paramθtre ()
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
}
bootstrap();
Finalementは、La Fonctionアプリを待つ.Love port 3000を参照してください.
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(3000)
}
bootstrap()
IL NE RESTプラスqu ' se retourner dansルターミナルは、トランスポーターとテスターNotre Superbe APIを注ぎます.

コンパイラ、ランサーetテスター
デRetour Dansルターミナル、ピート利用者La Commandeの上でtsc EE PARスクリプトをインストールしてください.
node_modules/.bin/tsc
CONTERDEを通してのPutランサーNotre APIについて
node dist/main.js
ETテンス,『家族の家族』について
curl http://localhost:3000

<論説>ヘーリュー・ド-ルの所説をめぐって
☎️ Discord Webeleon
🎁 Code sur github