본문 바로가기

nodejs

(12)
또 사용할것 같은 custom 함수들 - chunk array function chunk(array: object[], size: number) { const chunked: object[] = []; let index = 0; while (index setTimeout(resolve, ms)); }
@nestjs-modules/ioredis로 redis queue 사용하기 redis in nestjs 로 검색하면 많은 정보가 나오는데 거의다 cache로 사용하는 예제이다. 그런데 최근에 nestjs팀에서 ioredis 전용 라이브러리를 업데이트 해주셨다. 덕분에 아주 간단하게 연결해서 사용할수 있었다. 짧게 연결 법부터 적용 방법을 기록한다 ! 라이브러리 설치 $ yarn add @nestjs-modules/ioredis ioredis 연결하기 import { RedisModule } from '@nestjs-modules/ioredis'; @Module({ imports: [ RedisModule.forRoot({ config: { url: `redis://${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`, password: ..
redis connect redis 라이브러리 사용시 연결 하는법 https://www.npmjs.com/package/redis redis A modern, high performance Redis client. Latest version: 4.1.0, last published: a month ago. Start using redis in your project by running `npm i redis`. There are 8397 other projects in the npm registry using redis. www.npmjs.com 해당 라이브러리 4 버전기준, username 이 default 일때 연결하는 법은 다음과 같다. import { createClient } from 'redis'; const url ..
typescript 꿀팁 🎈 value check 🎵 check if value in enum 🎵 check if value in json object findValue in enumOrJsonValue 🎵 find in json array values.find((e) => e.no == wnatNo ); 🎵 check if object is empty Object.keys(value).length === 0 🎈 loop 🎵 for ... of with index const array1 = ['a', 'b', 'c']; for (const [i, v] of array1.entries()) { } 🎇 online editor https://www.typescriptlang.org/play
typeorm repository 뿌수기 👓 IN array import { In } from 'typeorm'; repository.find({where: { id : In(idArr)}}); https://github.com/typeorm/typeorm/issues/1239#issuecomment-367207538 👓 LIKE repository.find({ where : { name : Like(`%${name}%`)} }); repository.find({ where : { name : Like(`%${escapeLikeString(htmlentities(name))}%`)} }); // 특수 문자 처리 export const htmlentities = (value: string) => value.replace(/[\u00A0-\u999..
jwt role guard 적용기 ✨ jwt + role guard 를 적용해 보자 ! jwt 인증과 payload 에 심어진 role로 guard 를 적용하자 (예시를 위하여 jwt access token은 post 요청시 body에 id 와 role 을 전달하면 받을수 있게 함 !) install yarn add @nestjs/config @nestjs/jwt @nestjs/passport passport passport-jwt 공통 적으로 사용하는 값들 export enum Role { role1 = 'role1', role2 = 'role2', } export class AuthDto { @ApiProperty() @IsString() id: string; @ApiProperty() @IsEnum(Ro..
aws s3 endpoint 적용기 ✔ aws-sdk 라이브러리 사용 시 endpoint 변경을 적용해보자 nestjs - service layer 에서 적용했다. import * as AWS from 'aws-sdk'; export class S3Service { private readonly s3: AWS.S3; private readonly bucketName = process.env.S3_BUCKET_NAME; constructor() { this.s3 = new AWS.S3({ s3ForcePathStyle: true, endpoint: process.env.S3_BASE_URL, accessKeyId: process.env.S3_ACCESS_KEY, secretAccessKey: process.env.S3_SECRET_KEY, ..
eslint-plugin-import in nestjs install $ yarn add eslint-plugin-import .eslintrc.js plugins : [import], extends : ['plugin:import/recommended'], rules : { 'import/order': ['error', { alphabetize: { order: 'asc' }, groups: [ ['builtin', 'external','internal'], ], pathGroups: [ { pattern: '@*/**', group: 'external', position: 'before', }, { pattern: '#*/**', group: 'internal', position: 'after'} ], 'newlines-between': 'always' ..