NodeJS
-
Nestjs tutorialNodeJS 2021. 1. 11. 04:26
Nestjs tutorial 1. 프로젝트 생성하기 nestjs cli 를 이용하면 쉽게 프로젝트를 생성 할수 있습니다. # nestjs cli 설치 $ npm i -g @nestjs/cli # 프로젝트 생성 $ nest new project-name2. OpenAPI 설정 다음 라이브러리를 설치합니다. $ npm install --save @nestjs/swagger swagger-ui-express 이후 main.ts에 SwaggerModule 설정을 합니다 # main.ts import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import { NestExpressAppli..
-
typeorm에서 merge 예제NodeJS 2021. 1. 11. 04:26
typeorm에서 merge 예제 데이터가 있을 경우 update, 없을 경우 insert를 처리 하는 코드 예제 입니다. await this.eventsRepository .createQueryBuilder() .insert() .into(Event) .values(event) .orUpdate({ conflict_target: ['wp_id'], overwrite: ['cntnt', 'srch_wrd_seq', 'writr_nm', 'writr_id', 'tgtr_nm', 'tgtr_id', 'mod_dtm'] }) .execute();orUpdate의 conflict_target에 중복..
-
Mongoose에서 Array 내용 수정 후 .save()를 호출해도 동작하지 않는 현상NodeJS 2021. 1. 10. 04:24
Mongoose에서 Array 내용 수정 후 .save()를 호출해도 동작하지 않는 현상 다음과 같은 mongo Model이 존재 할때, const mongoose = require('mongoose'); const { Schema } = mongoose; const Confirm = new Schema({ type: { type: String, require: true, index: true }, pgm_id: { type: Number, require: true, index: true }, confirm: { type: Array, index: true }, brd_dtm: { type: Date, require: true, index: true }, }, { timestamps: tr..
-
nestjs에서 passport를 이용해서 로그인 하는 기능을 확인해보았습니다.NodeJS 2021. 1. 9. 04:24
nestjs에서 passport를 이용해서 로그인 하는 기능을 확인해보았습니다. 오늘은 nestjs에서 passport(Local) 예제에 SAML 연동 예제를 작성해서 PR을 보냈습니다. 다른 예제도 있었지만, 이 예제가 가장 심플하게 구성되어 있네요. 도움받은 것을 다시 나누기 위해서 요즘 PR을 열심히 작성하고 있습니다. 혹시 nestjs에서 passport 연동을 테스트 해보고 싶으시면 예제를 보셔요 물론 nestjs에서 제공되는 샘플이 있지만, 조각 코드라 실제로 구동하긴 어렵습니다. 또한 각 url의 설명을 Swagger document를 이용해서 작성했습니다. 참고자료 test-auth-chapter-sample NestJS Authenticated sessions documentation ..
-
JS] typeof를 이용해서 선언되지 않은 변수 확인NodeJS 2021. 1. 9. 04:22
JS] typeof를 이용해서 선언되지 않은 변수 확인 typeof 연산자는 피연산자의 평가 전 자료형을 나타내는 문자열을 반환합니다. 값이 없는 변수와 선언되지 않은 변수에 대한 처리를 어떻게 하시나요? 일반적으로 값이 없는 변수는 undefined를 가지고 있습니다. var a; console.log(a); // undefined // 처리 방법 // a의 값이 있을 때만 처리 if(a){ }자 그럼, 선언되지 않은 변수를 사용하면 어떻게 될까요? console.log(b); // ReferenceError: b is not defined // ReferenceError: b is not defined if(b) { console.log('b'); } 선언되지 않는 변수와 값이 없는 변..
-
Node express에서 Content Security Policy(CSP) 처리 하기NodeJS 2021. 1. 8. 04:21
Node express에서 Content Security Policy(CSP) 처리 하기 Google Analytics를 사용하면 CSP 오류가 발생하기도 합니다. 이때 쉽게 처리 하기 위해서는 helmet 라이브러리의 contentSecurityPolicy 옵션을 false로 변경하면 됩니다. app.use( helmet({ contentSecurityPolicy: false, }) );Google Analytics에서는 inline script를 사용하기 때문에, 일반적으로 CSP 처리를 위해 복잡한 설정을 사용하게 됩니다. 참고 자료 Content Security Policy (CSP) Google Analytics helmet
-
Node에서 mssql 사용하기NodeJS 2021. 1. 8. 04:21
Node에서 mssql 사용하기 단독으로 mssql을 사용할 경우 참고하세요. mssql라이브러리를 참고해서 간략하게 사용하는 예제입니다. 설치는 다음과 같습니다. $ npm install mssql기본 사용은 가이드에 다음과 같이 나옵니다. const sql = require('mssql') async () => { try { // make sure that any items are correctly URL encoded in the connection string await sql.connect('mssql://username:password@localhost/database') const result = await sql.query`select * from mytable..
-
디렉토리에서 중복된 파일을 찾을때 사용합니다.NodeJS 2021. 1. 6. 04:19
중복 파일 검색 프로젝트 바로가기 파일 관리를 잘 안하기 때문에 특정 디렉토리의 경우 중복된 파일이 다수 존재 합니다. 이를 확인하는 단순한 로직을 작성하였습니다. md5 hash를 이용해서 파일의 hash정보로 비교 하여 더 정확하게 중복된 파일을 확인합니다. 사용법 : node index.js ./검색디렉토리/검색파일형식 $> node index.js ./searchPath/**/*.txt $> node index.js **/* 시작 디렉테로를 상위로 이동시키기 위해서는 ../../ (한 개만 사용하면 동작 안함)를 사용해야 한다. LINUX에서는 상대 경로만 동작한다. (윈도우에서는 절대 경로도 잘 동작함) TODO : LINUX 절대 경로 동작 처리 & 상위 디렉토리 이상 동작 원인 분석 & 처리..