1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Nestjs 入門してみた

Last updated at Posted at 2023-08-09

背景

最近GreenとかYoutrustをみると、フロントもサーバーもTypeScript使ってますというところがかなり多い。確かにTypeScriptで統一できれば開発効率はよさそう。サーバー側はNestjsってやつが主流っぽい?(私の小さな観測範囲)ので、ちょっと入門してみる

環境

  • WSL(Ubuntu 22.04)

概要

  • 内部でExpressを使用している
    • オプションでFastify(早いらしい)を使用するように構成することもできる
    • Nest は任意の Node HTTP フレームワークと連携できる
  • Angularの影響を受けている

Hello Worldまで

NestCLI をインストール

$ npm i -g @nestjs/cli

サンプルプロジェクト作成

$ nest new sample-nest

image.png

できたプロジェクトをvscodeで開く

image.png

デフォルトでいろいろできてる状態になってる

起動

$ npm run start
$ npm run start:dev # ファイルの変更監視をする場合

localhost:3000 にアクセス

image.png

SWCビルダー

開発プロセスを高速化する (ビルドを 20 倍高速化する) には、次のようにフラグをスクリプトに渡すことでSWC ビルダーを使用できます。 -b swcstartnpm run start -- -b swc

という記述があるので、SWCビルダーを調べてみた。

SWC (Speedy Web Compiler) は、コンパイルとバンドルの両方に使用できる拡張可能な Rust ベースのプラットフォームです。Nest CLI で SWC を使用することは、開発プロセスを大幅にスピードアップするための優れた簡単な方法です。

ドキュメントをみるに確かに早そうだが、設定が必要らしい。いったん飛ばす。

ホットリロード

npm run start:dev で一応されるっぽいが、自動でブラウザはリロードされない。手動リロード必要。

LinterとFormatter

デフォルトでeslintとprettierが設定されている。

備考

公式ドキュメントが丁寧なのでそれ読めばよさそう。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?