Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

nest js env validation

import { plainToClass } from 'class-transformer';
import { IsEnum, IsNumber, validateSync } from 'class-validator';

enum Environment {
  Development = "development",
  Production = "production",
  Test = "test",
  Provision = "provision",
}

class EnvironmentVariables {
  @IsEnum(Environment)
  NODE_ENV: Environment;

  @IsNumber()
  PORT: number;
}

export function validate(config: Record<string, unknown>) {
  const validatedConfig = plainToClass(
    EnvironmentVariables,
    config,
    { enableImplicitConversion: true },
  );
  const errors = validateSync(validatedConfig, { skipMissingProperties: false });

  if (errors.length > 0) {
    throw new Error(errors.toString());
  }
  return validatedConfig;
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: print gets opened whenever pdf is opened 
Typescript :: how to css after elements for background overlays 
Typescript :: to move previous month 
Typescript :: sap abap check file exists on application server tcode 
Typescript :: powershell check if the sql server ports are dynamic 
Typescript :: nullish coalescing angular example 
Typescript :: sourcetree winmerge arguments three way merge 
Typescript :: collection that accepts duplicate keys 
Typescript :: localstorage getitem angular 
Typescript :: typescript enum get key by value 
Typescript :: nunjucks if logical or 
Typescript :: pull rewuests in local project 
Typescript :: which of the foolowing ia an element of pallette that holds multiple elements of nspecific purpose 
Typescript :: adding html in typescript 
Typescript :: Update multiple documents with different field value by id set. Mongoose 
Typescript :: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in 
Typescript :: body massage centers in kochi 
Typescript :: install vsts client version 14.102.0 
Cpp :: c++ starter 
Cpp :: c++ vector decimal to binary 
Cpp :: qt qstring to float 
Cpp :: vhdl integer to std_logic_vector 
Cpp :: unordered_map of pair and int 
Cpp :: how to initialized a 2d vector 
Cpp :: c++ min 
Cpp :: qimage transformed 
Cpp :: can you chnage the address of a pointer 
Cpp :: how to make a sqlite3 object in cpp 
Cpp :: std::tuple apply multiplier 
Cpp :: shout sharkest 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =