본문 바로가기
반응형

전체 글281

[js, ts] 함수를 파일로 따로 빼서 정리하는 방법 [JavaScript, TypeScript] 함수를 파일로 따로 빼서 정리하는 방법 만들고 싶은 함수를 정리한 예를 들면 calculator.ts 파일을 만든다. const plus = (number1: number, number2: number): number => { return number1 + number2; }; const minus = (number1: number, number2: number): number => { return number1 - number2; }; const multiply = (number1: number, number2: number): number => { return number1 * number2; }; const divide = (number1: number,.. 2023. 3. 5.
[Next.js] 개발환경 구축 및 Next.js 13으로 업데이트 [Next.js] 개발환경 구축 명령어 및 Next.js 13으로 업데이트 명령어 Next.js 시작 $ npx create-next-app@latest $ yarn create next-app $ pnpm create next-app 위 3개 명령어 중 하나로 설치 TypeScript 프로젝트로 시작하려면 --typescript 플래그를 사용할 수 있다. $ npx create-next-app@latest --typescript $ yarn create next-app --typescript $ pnpm create next-app --typescript 위 3개 명령어 중 하나로 설치 react 및 react-dom 프로젝트에서 다음을 설치 $ npm install next react react-do.. 2023. 3. 4.
[NestJS] @ValidationNested로 하위 연관 dto 검증하기 1. ValidationPipe = @Type, 2. 하위 연관 dto 검증 = @ValidateNested 아래 코드의 문제점 export class UserInfo { @ApiProperty({ type: Date }) @IsDateString() @IsOptional() @prop() playTime?: Date; @prop({ type: () => userStrongInfo }) @ApiProperty({ type: () => userStrongInfo }) @IsDefined() @Type(() => userStrongInfo) public userPower: userStrongInfo; @prop({ type: () => userBaseInfo }) @ApiProperty({ descripti.. 2023. 3. 4.
[Typegoose] 하위 개체의 _id를 없애는 방법, @prop({ _id: false}) Typegoose에서 하위 개체의 _id를 없애는 방법은 @prop({ _id: false})이다. 예시 클래스의 구성은 다음과 같다.export class UserInfo { @ApiProperty({ type: Date }) @IsDateString() @IsOptional() @prop() playTime?: Date; @prop({ type: () => userStrongInfo, _id: false }) @ApiProperty() @IsDefined() @Type(() => userStrongInfo) public userPower: userStrongInfo; @prop({ type: () => userBaseInfo, _id: false }) @ApiProperty({ .. 2023. 3. 3.
mongoose, typegoose, nestjs-typegoose, kindagoose 사용이유 mongoose => typegoose, nestjs-typegoose => kindagoose 사용이유 Mongoose 1. MongoDB와 Express.js 웹 애플리케이션 프레임워크 간 연결을 생성하는 자바스크립트 객체지향 프로그래밍 라이브러리이다. 2. Node.js와 MongoDB를 연결해주는 ODM이다. * ODM(Object Documnet Mapping): 객체와 문서를 1대1로 매칭하는 역할을 한다. 3. Node.js기반 프레임 워크들에서도 사용 가능하다. (NestJS와 같은 Express기반 프레임워크 또한 가능) Typegoose TypeScript와 함께 Mongoose를 사용할 때 Mongoose 모델과 TypeScript 인터페이스를 모두 정의해야 한다는 문제 - 모델이 변.. 2023. 3. 3.
mongoose, typegoose, nestjs-typegoose, kindagoose 설치 명령어 mongoose, typegoose, nestjs-typegoose, kindagoose 설치 명령어 mongoose https://mongoosejs.com/ Mongoose ODM v7.0.0 Let's face it, writing MongoDB validation, casting and business logic boilerplate is a drag. That's why we wrote Mongoose. const mongoose = require('mongoose'); mongoose.connect('mongodb://127.0.0.1:27017/test'); const Cat = mongoose.model('Cat', { name: mongoosejs.com npm으로 설치 $ npm ins.. 2023. 3. 3.
[Mongoose] strictQuery란? (Strict, Implicit $in) strictQuery, Strict와 차이점, strictQuery 옵션 종류,  Implicit $in strictQuery란?Mongoose는 쿼리 필터에 대한 strict 모드를 피하기 위해 별도의 strictQuery 옵션을 지원한다.빈 쿼리 필터로 인해 Mongoose가 모델의 모든 문서를 반환하여 문제가 발생할 수 있기 때문이다.const mySchema = new Schema({ field: Number }, { strict: true });const MyModel = mongoose.model('Test', mySchema);MyModel.find({ notInSchema: 1 });문제점: Mongoose는 'strict: true' 때문에 'notInSchema: 1'을 필터링합니다. .. 2023. 3. 2.
[Mongoose] Query Casting Query Casting: Model.find(), Query.prototype.find(), Model.findOne(), Query.prototype.findOne() Model.find(), Query.prototype.find(), Model.findOne(), Query.prototype.findOne() 등의 첫 번째 매개변수를 filter(필터)라고 한고 이 매개변수는 쿼리 또는 조건이라고도 한다. 예시코드) const query = Character.find({ name: '홍길동' }); query.getFilter(); // `{ name: '홍길동' }` // 후속 연결 호출은 새 속성을 필터에 병합한다. query.find({ age: { $gt: 50 } }); query.getF.. 2023. 3. 2.
[Mongoose] Model.events, Model관련 Error 처리 [Mongoose] Model.events, Model관련 NestJS Error 처리 및 try.. catch문클린코드 Model.events 1. 발생한 오류를 보고하는 이벤트 이미터. 전역 오류 처리에 유용하다. 2. Model 관련 Method를 처리할 때 따로 try.. catch문을 사용하지 않아도 된다. 예시코드) MyModel.events.on('error', err => console.log(err.message)); await MyModel.findOne({ _id: 'Not a valid ObjectId' }).catch(noop); 출력값 Cast to ObjectId failed for value "Not a valid ObjectId" (type string) at path "_.. 2023. 3. 1.
[서버용어] 스케일 업(Scale-up), 스케일 아웃(Scale-out), 스케일 인(Scale-in), 스케일 다운(Scale-down) 스케일 업(Scale-up), 스케일 아웃(Scale-out)이란? 스케일 업 (Scale-up) 1. 성능이나 용량 증강을 목적으로 하나의 서버에 디스크를 추가하거나 CPU나 메모리를 업그레이드시키는 것을 말한다. 2. 하나의 서버의 능력을 증강하기 때문에 수직 스케일링(vertical scaling)이라고도 한다. 3. 즉, 기존의 하드웨어를 보다 높은 사양으로 업그레이드하는 것을 말한다. 스케일 아웃 (Scale-out) 1. 기존의 서버와 같은 사양 또는 비슷한 사양의 서버 대수를 증가시키는 방법으로 처리 능력을 향샹시키는 것을 말한다. 2. 스케일 아웃 방식을 "수평 스케일"이라고 부르기도 하고, 확장이 스케일 업보다는 다소 유연하다. 3. 1의 처리 능력을 가진 서버에 동일한 서버 4대를 더 .. 2023. 3. 1.
반응형