本文へスキップ
製品デスクトップツールTASTECAD図面の確認TASTEFILESファイル管理TASTEFTPファイル転送TASTESSHリモートワークスペースTASTEZIP圧縮と展開TASTEWINMファイル管理開発ツールTASTECODERust 統合開発環境TASTESTUDIO統合開発・テスト環境TASTEETLデータ統合(ETL)サーバーTASTEREMOTEリモートデスクトップサーバーTASTEGEO空間情報サーバーTASTEMAILメールワークスペース投資TASTESTOCK株式自動売買デスクトップアプリはじめるダウンロードドキュメント購入すべての製品
マーケットプレイス
ニュース
技術ニュース今日の開発ニュース開発ドキュメントプログラミング言語RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWebフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngularサーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Expressアプリ・デスクトップ フレームワークTauriFlutterReact NativeElectronアルゴリズムアルゴリズムの基礎主要アルゴリズム発展アルゴリズム実務のアルゴリズム
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケースコミュニティガイド
協業技術移転ウェブサイト構築デスクトップアプリ構築リリース・決済パイプライン販売パートナーお問い合わせ
サービスリモートデスクトップインストールパッケージのカスタマイズ
TASTEDEV
製品

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらくTASTEWINM2つの画面で整理する、キーボード中心のファイルマネージャー

開発ツール

TASTECODERust アプリの編集・ビルド・デバッグ・テストまでひとつのウィンドウでTASTESTUDIO編集からリモートテスト、承認した AI 修正までTASTEETL値を見ながら、データを運ぶ

サーバー

TASTEREMOTE自社サーバーで運用するリモートデスクトップTASTEGEOGeoServer 互換の空間情報サーバーを Rust で作り直しますTASTEMAILメールの主導権を、もう一度自分の手に

投資

TASTESTOCKいつ・何を。自分で決めたルールどおりに動く株式自動売買

はじめる

ダウンロード全製品の最新版ドキュメント各製品の使い方購入サブスクリプション・永久ライセンスすべての製品全製品を一覧で
すべての製品
マーケットプレイスニュース
技術

ニュース

今日の開発ニュース言語・フレームワーク・GitHub・AI の公式発表開発ドキュメント言語・フレームワーク・アルゴリズムのガイド

プログラミング言語

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

フレームワーク

Webフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngular
サーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
アプリ・デスクトップ フレームワークTauriFlutterReact NativeElectron

アルゴリズム

アルゴリズムの基礎計算量解析 · ソート · 探索 · 基本データ構造 · 木構造とヒープ主要アルゴリズムグラフ探索 · 最短経路と最小全域木 · 動的計画法 · 貪欲法 · 分割統治法 · バックトラッキング発展アルゴリズム文字列アルゴリズム · 数学と整数論 · ビット演算 · セグメント木 · Union-Find実務のアルゴリズムコーディング面接対策 · LRUキャッシュ · レート制限 · コンシステントハッシュ法
開発ドキュメントをすべて見る
コミュニティ
プロジェクトビルダーと作品を探す開発ログ決定と試行錯誤プロンプト再利用できる指示AIツールの問題Claude・Codex・Gemini の問題と回避策ショーケース完成した成果コミュニティガイドオープンにつくる方法
協業
技術移転Rust・egui でネイティブアプリを作るウェブサイト構築10言語、アカウント、ドキュメントとダウンロードデスクトップアプリ構築Rust・egui、WebView なしリリース・決済パイプライン署名・MSI・deb・rpm・AppImage・ハッシュ販売パートナー紹介して決済額の30%お問い合わせ構築・提携・投資のご相談
サービス
リモートデスクトップブラウザから自分のパソコンへインストールパッケージのカスタマイズ必要な機能だけ、設定は事前に
購入
JA
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
ログイン
ログイン
TASTEDEV

小さなツールから、より良い開発へ。

support@tastedev.netTASTEDEVを支援
製品製品ラインナップ購入ドキュメントダウンロードマーケットプレイスサポート
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケース
ポリシー会社概要プライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
昨日
累計閲覧
商号
GXSOFT
代表者
CHOI YOUNG GU
事業者登録番号
853-44-00368
所在地
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
メール
whitecalvin@tastedev.net
個人情報保護責任者
CHOI YOUNG GU

© 2026 TASTEDEV製品情報は検証済みの開発ソースに基づいています。リリース・改善中

NestJS · Express ドキュメント
NestJS · Express
Getting Started with NestJS and ExpressProject StructureCore ConceptsValidation, Configuration and DatabasesTestingDeployment
ディスカッション

NestJS · Express ガイド · 4/6

Validation, Configuration and Databases

この章は現在、英語でのみ提供しています。

Data enters a server through request bodies, gets validated, and ends up in a database. This chapter covers validation with ValidationPipe and class-validator, reading environment variables with the config module, and database access through an ORM.

Where state belongs

Nest providers are singletons by default, shared across the whole app. Storing per-request values in service fields can leak data between users. Keep state that must outlive a request in a database or an external store such as Redis, and keep the server process stateless so multiple instances behave the same.

Validating input with DTOs and ValidationPipe

Describe request bodies with DTO (data transfer object) classes and attach rules with class-validator decorators.

npm i class-validator class-transformer
// src/users/dto/create-user.dto.ts
import { IsEmail, IsInt, IsOptional, IsString, Length, Min } from "class-validator";

export class CreateUserDto {
  @IsString()
  @Length(2, 30)
  name: string;

  @IsEmail()
  email: string;

  @IsOptional()
  @IsInt()
  @Min(0)
  age?: number;
}

Register ValidationPipe globally in main.ts and every DTO received with @Body() is checked automatically; invalid input gets a 400 response listing the errors.

// src/main.ts
import { ValidationPipe } from "@nestjs/common";
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.useGlobalPipes(
    new ValidationPipe({
      whitelist: true, // strip properties not in the DTO
      forbidNonWhitelisted: true, // or reject them with 400
      transform: true, // turn plain objects into DTO instances
    }),
  );
  await app.listen(process.env.PORT ?? 3000);
}
bootstrap();

In a controller, just type the parameter: create(@Body() dto: CreateUserDto). For updates, PartialType(CreateUserDto) from @nestjs/mapped-types makes every property optional; nest g resource generates UpdateUserDto this way.

Reading configuration

Keep database URLs and secrets out of code. ConfigModule from @nestjs/config loads a .env file plus real environment variables and exposes them through ConfigService.

npm i @nestjs/config

With ConfigModule.forRoot({ isGlobal: true }) in the root module (shown below), any provider can inject ConfigService and call this.config.get<string>("DATABASE_URL"). Real environment variables take precedence over .env, and stays out of version control.

この章について質問がありますか?
前の章Core Concepts次の章Testing
.env

Connecting a database with TypeORM

Nest provides an official TypeORM integration, @nestjs/typeorm. For PostgreSQL, install it with the driver.

npm i @nestjs/typeorm typeorm pg

Define tables as entity classes, configure the connection in the root module, and register entities in feature modules.

// src/users/entities/user.entity.ts
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @Column({ unique: true })
  email: string;
}
// src/app.module.ts
import { Module } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { TypeOrmModule } from "@nestjs/typeorm";
import { UsersModule } from "./users/users.module";

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    TypeOrmModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (config: ConfigService) => ({
        type: "postgres",
        url: config.get<string>("DATABASE_URL"),
        autoLoadEntities: true,
        synchronize: false, // use migrations in production
      }),
    }),
    UsersModule,
  ],
})
export class AppModule {}

Add TypeOrmModule.forFeature([User]) to the imports of UsersModule, then inject the repository with @InjectRepository.

import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";
import { CreateUserDto } from "./dto/create-user.dto";
import { User } from "./entities/user.entity";

@Injectable()
export class UsersService {
  constructor(@InjectRepository(User) private readonly users: Repository<User>) {}

  findAll() {
    return this.users.find();
  }

  create(dto: CreateUserDto) {
    return this.users.save(this.users.create(dto));
  }
}

synchronize: true alters the schema to match your entities. It is handy early on but can drop data, so turn it off in production and manage the schema with TypeORM migrations.

Using Prisma instead

Prisma is an ORM where you describe models in schema.prisma and generate a typed client from it. Start with npm i -D prisma and npx prisma init, and create and apply migrations with npx prisma migrate dev. There is no official Nest module; the usual pattern is a PrismaService provider wrapping the generated PrismaClient, connecting in onModuleInit, and injected into other services. Client output location and setup differ between Prisma releases, so follow the NestJS guide in Prisma's docs.

In plain Express

Express ships no validation or data layer. Parse bodies with express.json(), validate with a library such as Zod or Joi, and expose your ORM or driver from a module your routers import. You design yourself what Nest organizes with modules and dependency injection.

Summary

  • Providers are shared, so keep per-request state out of fields and store durable state externally.
  • Define rules on DTOs with class-validator and validate automatically with a global ValidationPipe.
  • Read environment variables through ConfigModule and ConfigService.
  • Connect TypeORM through @nestjs/typeorm and inject repositories; wire Prisma through your own PrismaService.

コメント 0件

人気のコメント順新しい順

ログイン · ログインするとコメントできます。