Skip to main content
ProductsDesktop toolsTASTECADDrawing reviewTASTEFILESFile managementTASTEFTPFile transferTASTESSHRemote workspaceTASTEZIPCompression and extractionTASTEWINMFile managementDeveloper toolsTASTECODERust integrated development environmentTASTESTUDIOIntegrated development and test environmentTASTEETLData integration (ETL)ServersTASTEREMOTERemote desktop serverTASTEGEOGeospatial serverTASTEMAILMail workspaceInvestingTASTESTOCKStock auto-trading desktop appGet startedDownloadsDocumentationBuyAll products
Marketplace
News
TechNewsToday's dev newsDeveloper docsProgramming languagesRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWeb front-end frameworksNext.jsReactVue.js · NuxtSvelteKitAngularServer frameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressApp & desktop frameworksTauriFlutterReact NativeElectronAlgorithmsAlgorithm basicsCore algorithmsAdvanced algorithmsPractical algorithms
CommunityProjectsDevelopment logsPromptsAI tool issuesShowcaseCommunity guide
Work with usTech transferWebsite buildDesktop app buildRelease and payment pipelineSales partnerContact
ServicesRemote desktopCustom installer packages
TASTEDEV
Products

Desktop tools

TASTECADComplex drawings, opened with easeTASTEFILESJust the files you need, as fast as possibleTASTEFTPThe tidiest path for your filesTASTESSHA stronger link between you and your serversTASTEZIPPack faster, unpack saferTASTEWINMA keyboard-first file manager with two panes

Developer tools

TASTECODEEdit, build, debug and test Rust apps in one windowTASTESTUDIOFrom editing to remote tests and approved AI fixesTASTEETLMove data while you watch the values

Servers

TASTEREMOTEA remote desktop you run on your own serverTASTEGEORebuilding a GeoServer-compatible geospatial server in RustTASTEMAILTake back control of your email

Investing

TASTESTOCKStock auto-trading that follows the rules you set: when, and what

Get started

DownloadsLatest builds of every productDocsHow to use each productBuySubscriptions and perpetual licencesAll productsEvery product at a glance
All products
MarketplaceNews
Tech

News

Today's dev newsOfficial announcements on languages, frameworks, GitHub and AIDeveloper docsGuides to languages, frameworks and algorithms

Programming languages

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Frameworks

Web front-end frameworksNext.jsReactVue.js · NuxtSvelteKitAngular
Server frameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
App & desktop frameworksTauriFlutterReact NativeElectron

Algorithms

Algorithm basicsComplexity analysis · Sorting · Searching · Basic data structures · Trees and heapsCore algorithmsGraph traversal · Shortest paths & minimum spanning trees · Dynamic programming · Greedy algorithms · Divide and conquer · BacktrackingAdvanced algorithmsString algorithms · Math and number theory · Bit manipulation · Segment trees · Union-findPractical algorithmsCoding interview strategy · LRU cache · Rate limiting · Consistent hashing
All development docs
Community
ProjectsDiscover builders and their workDevelopment logsDecisions and lessons learnedPromptsReusable instructionsAI tool issuesProblems and workarounds for Claude, Codex, GeminiShowcaseFinished resultsCommunity guideHow we build in the open
Work with us
Tech transferNative apps in Rust and eguiWebsite build10 languages, accounts, docs and downloadsDesktop app buildRust and egui, no WebViewRelease and payment pipelineSigning, MSI, deb, rpm, AppImage, hashesSales partnerRecommend us and earn 30%ContactBuilds, partnerships and investment
Services
Remote desktopReach your computer from a browserCustom installer packagesOnly the features you need, settings preloaded
Buy
EN
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Log in
Log in
TASTEDEV

From small tools to better development.

support@tastedev.netSupport TASTEDEV
ProductsProduct lineupBuyDocsDownloadsMarketplaceSupport
CommunityProjectsDevelopment logsPromptsAI tool issuesShowcase
PoliciesAbout usPrivacy policyTerms of serviceSubscription termsRefund policyCommunity guidelines
AccountLog inSign up
Visitors
Today
Yesterday
Total views
Company
GXSOFT
Representative
CHOI YOUNG GU
Business registration number
853-44-00368
Address
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Phone
+82-10-4404-1523
Email
whitecalvin@tastedev.net
Privacy officer
CHOI YOUNG GU

© 2026 TASTEDEVProduct information is based on verified development sources.Released · improving

NestJS · Express docs
NestJS · Express
Getting Started with NestJS and ExpressProject StructureCore ConceptsValidation, Configuration and DatabasesTestingDeployment
Discussions

NestJS · Express guide · 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 .env stays out of version control.

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.
Questions about this chapter?
Previous chapterCore ConceptsNext chapterTesting

0 comments

Top commentsNewest first

Sign in · Sign in to leave a comment.