본문 바로가기

Nodejs

[NestJS] 프로젝트 설정 01 목표: prettierrc 설정 / .env 설정 .prettierrc{ "arrowParens": "always", "printWidth": 150, "trailingComma": "es5", "semi": true, "singleQuote": false, "endOfLine": "auto", "tabWidth": 2, "useTabs": false}선호하는 설정으로 변경.[탭은 2칸, 줄길이는 최대 150, doubleQuote]변경했으면yarn format* 변경 이후 VS Code 버그인지, 빨간줄 쳐지고 바로 적용안되는 이슈 있음. 재실행 한번 해줘야 함. .env 설정env는 총 3가지로 생성 .env, .env.development, .env.local(.gitiIgnore)... 더보기
[NestJS] 시작하기 00 https://docs.nestjs.com/first-steps참고 Documentation | NestJS - A progressive Node.js frameworkNest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Readocs.nestjs.com  npm i -g @nestjs/cli nest new ... 더보기
TypeScript tsconfig-paths 톺아보기 tsconfig-paths는 TypeScript 프로젝트에서 모듈 해석과 경로 매핑을 간소화하는 라이브러리입니다. 아래는 tsconfig-paths의 설치, 설정 및 사용법, 코드로 구현하는 방법에 대한 설명입니다.설치방법tsconfig-paths를 설치할 때는 dev 모드로 설치합니다.npm install tsconfig-paths --save-devtsconfig-paths 설정하기tsconfig.json에서 설정하기아래와 같이 tsconfig.json 파일에서 paths에 alias를 설정합니다."complieOption": { "baseUrl": "./", "paths": { "@/*": ["src/*"]}}tsconfig.paths.json 별도 파일로 .. 더보기
Typescript tsconfig.json 옵션들 톺아보기 Typescript로 프로젝트를 진행하다보면 정말 많은 tsconfig 옵션을 만날 수 있습니다. 실제로 그중에서 사용하는 옵션은 몇개 안되고, 주석이 되어 있는데, 우리가 많이 사용하는 옵션들과 잘 사용하지 않는 옵션들에 대해서 한번 살펴봅시다.tsc --init 할 때, 활성 되는 옵션target: JavaScript 코드의 ECMAScript 버전을 설정하는 데 사용됩니다"es3": ECMAScript 3 (ES3) 버전을 대상으로 합니다. 이는 가장 오래된 ECMAScript 버전으로, 모든 브라우저에서 지원됩니다."es5": ECMAScript 5 (ES5) 버전을 대상으로 합니다. ES5는 ES3의 확장으로, IE 9 및 모던 브라우저에서 지원됩니다."es2015" 또는 "es6": ECMAS.. 더보기
Node.js 백엔드 디렉토리 구조 매번 신규 프로젝트를 구성할 때 마다 프로젝트 구조를 어떻게 잡는 것이 좋을까 고민이 됩니다. 보통 2가지 방법으로 구성하는 것 같아요. 기능 중심으로 구성하기 도메인 중심으로 구성하기 뭐가 좋다 라고 하기보다는 편한방식 또는 익숙한 방식으로 구성하는 것 같습니다. 대략적인 Node.js 백엔드 디렉토리 구조에 대한 설명과 구조를 살펴보겠습니다. 디렉토리 폴더 설명 @types/: 타입 정의 파일을 포함하는 디렉토리입니다. 주로 외부 라이브러리의 타입 선언 파일이 위치합니다. config/: 설정 파일을 포함하는 디렉토리입니다. 주로 환경 변수나 애플리케이션 설정과 관련된 파일들이 위치합니다. logs/: 로그 파일을 저장하는 디렉토리입니다. 애플리케이션 로그 또는 서버 로그와 관련된 파일들이 위치할 수.. 더보기
설치 1. yarn 설치 2. cmd > create-react-app hello-react d:\nodejs\reactjs\hello>cd hello-react d:\nodejs\reactjs\hello\hello-react>npm start > hello-react@0.1.0 start d:\nodejs\reactjs\hello\hello-react > react-scripts start 더보기
async / await 와 Promise (async 안에서 promise 처리) 상황#1 fn 함수를 async/await하고 싶은데, 그안에 비동기 함수(hasher)를 사용해야 할 때. 처리방법. 1. await를 사용할 함수를 생성. 2. return 타입을 Promise 객체로 넘겨준다. 3. promise 안에서 resolve로 넘겨줄 것과, reject로 넘겨줄 것을 만든다. 4. await로 받았을 때, 에러가 있을 수 있으므로, try-catch로 처리가 필요하다 *(중요) Promise 사용시 필수! console.log('hello'); const pbkdf = require('pbkdf2-password') const hasher = pbkdf(); console.log('hi1~') const fn = async ()=>{ const user={ id : '1'.. 더보기
[NODEJS 입문]14.(pbkdf2-password) 비밀번호 암호화 npm install --save pbkdf2-password 사용법 var bkfd2Password = require("pbkdf2-password"); var hasher = bkfd2Password(); var assert = require("assert"); var opts = { password: "helloworld" }; hasher(opts, function(err, pass, salt, hash) { opts.salt = salt; hasher(opts, function(err, pass, salt, hash2) { assert.deepEqual(hash2, hash); // password mismatch opts.password = "aaa"; hasher(opts, function(.. 더보기
[NODEJS 입문]13.(사용자 DELETE) 사용자 삭제 router.route('/user/delete') .get((req,res)=>{ res.render(path.join('.','user','delete'),{user : req.session.user}); }) form(action="/user/delete", method="post") input(type="hidden", name="_method" value='delete') input(type="hidden", name="username" value=user.username) input(type="submit", value="사용자 삭제") .delete((req,res)=>{ var temp ={ username : req.body.username, password : req.body.passw.. 더보기
[NODEJS 입문]12.(사용자 UPDATE) 사용자 정보 변경 사용자 정보를 변경한다. register pug 를 토대로 update pug를 생성 1. update /user/update router.route('/user/update') .get((req,res)=>{ res.render(path.join('.','user','update'),{user : req.session.user}); }) 2. update.pug -if(user){ form(action="/user/update", method="post") input(type="hidden", name="_method" value="PUT") div input(type='text' name='username' placeholder='username' value=user.username) div inpu.. 더보기