본문 바로가기

전체 글221

Node.js 개발환경 설치했던 것들 npm i express npm i jest -D npm i morgan cookie-parser express-session npm i --global rimraf npm i -D nodemon npm i -g express-generator express learn-express --view=pug npm i express-session connect-flash express learn-sequelize --views=pug npm i -g sequelize-cli sequelize init sequelize 사용 sequelize db:create mySQL npm i sequelize mysql2 MongoDB express learn-mongoose --view=pug mongoo.. 2019. 10. 1.
promisify : 콜백함수를 promise를 지원하게 만들기 crypto.randomBytes(64, (err, buf) =>{ const salt = buf.toString('base64'); console.log('salt', salt); console.time('암호화') crypto.pbkdf2('fabxoe바보', salt, 501395, 64, 'sha512', (err, key)=>{ console.log('password', key.toString('base64')); console.timeEnd('암호화'); }); }); 콜백지옥을 보여주고 있는 콜백함수. promise로 바꾸려고 해도 아무나 바꿀 수 있는게 아니다. 지원을 해줘야한다. 애초에 메서드를 만들때 내부를 Promise 생성자로 만들었어야 지원해준다. 그러나 지원하지 않는 콜백함수를 .. 2019. 9. 30.
crypto모듈을 이용한 암호화 단방향 암호화 hash방식 const crypto = require('crypto'); console.log(crypto.createHash('sha512').update('fabxoe바보').digest('base64')); hash방식은 복호화 되지 않는 문자열을 만든다. 로그인과 같이 일반적으로 암호화에는 복호화가 필요없다. 가입시 원래 비밀번호에 대한 정보없이 hash방식으로 만들어진 문자열만 서버에 저장해두고 다음 로그인시에는 웹사이트의 비밀번호란에 타이핑한 문자열을 hash방식으로 암호화 했을때 일치하는 문자열이 서버에 있는지만 확인하자. 있으면 통과 없으면 로그인 실패처리 하면 되기 때문이다. 그러나 실제 암호값과 같지 않아도 해시처리된 값의 결과가 하나 더 있을 수도 있다고 한다. (다른 .. 2019. 9. 30.
ES8(2017)에서의 변화 promise의 장점에도 불구하고 수행 순서를 명확히 하는데는 약점이 존재했다. Users.findOne('zero') .then((user) => { console.log(user); return Users.update('zero', 'nero'); }) .then((updatedUser) => { console.log(updatedUser); return Users.remove('nero'); }) .then((removedUsers) => { console.log(removedUser); }) .catch((err) => { console.error(error); }); console.log('다 찾았니?'); 예를 들어 console.log('다 찾았니?');는 findOne보다 먼저 실행되며 그.. 2019. 9. 30.
ES6(2015)에서의 변화 3 Users.findOne('zero', (err, user) => { if (err) { return console.error(err); } console.log(user); Users.update('zero', 'nero', (err, updatedUser) => { if (err) { return console.error(err); } console.log(updatedUser); Users.remove('nero', (error, removedUser) => { if (err) { return console.error(err); } console.log(removedUser); }); }); }); console.log('다 찾았니?'); 콜백을 사용하다 보면 깊이가 계속해서 깊어지는 콜백지옥을 경.. 2019. 9. 30.
ES6(2015)에서의 변화 2 var candyMachine = { status: { name: 'node', count: 5, }, getCandy(){ this.status.count--; return this.status.count; } }; 위 코드의 status과 geCandy를 별도의 변수로 가져오고 싶다면 const getCandy = candyMachine.getCandy const status = candyMachine.status 이러한 코드를 작성할 것이다. 특히나 객체 리터럴내 속성과 이름이 같은 변수를 만들어 담는다면 이를 한번에 한줄로 손쉽게 가져올 수 있는 문법이 생겼다. const { status, getCandy } = candyMachine destructuring이라 불리는 문법인데 c++의 소멸자도.. 2019. 9. 29.
ES6(2015)에서의 변화 1 var sayNode = function(){ console.log('Node'); }; var es = 'ES'; 준비 const oldObject = { sayJS: function() { console.log('JS'); }, sayNode:sayNode }; oldObject[es + 6]= 'Fantastic' 구버전문법 const newObject = { sayJS() { console.log('JS'); }, sayNode, [es + 6]: 'Fantastic' }; ES6에서의 간결해진 문법 (키와 값이 같은 항목은 한번만 타이핑 해도 된다. 동적할당을 리터럴 작성시 동시에 함께 작성가능해졌다.) oldObject.sayNode(); newObject.sayNode(); oldObject.. 2019. 9. 29.
Ant Design npm i antd 사이트: https://ant.design cdn주소: https://ant.design/docs/react/introduce 2019. 9. 28.
React 적용하기 C:\Users\fabxo\WebstormProjects\react-nodebird\front>npm init C:\Users\fabxo\WebstormProjects\react-nodebird\front>npm i react react-dom next C:\Users\fabxo\WebstormProjects\react-nodebird\front>npm i -D nodemon webpack C:\Users\fabxo\WebstormProjects\react-nodebird\front>npm i -D eslint init을 통해 package.json을 자동생성 하였다. 직접 만들어도 상관없다. { "parserOptions": { "ecmaVersion": 2018, "sourceType": "modul.. 2019. 9. 28.
합리적인 테스트 이름만들기 TDD라기 보다는 unit테스트에 대한 전반적인 팁이다. 테스트에 주석을 달기보다는 잘 지은 이름으로 문서화하자. 책에서는 ATM 도메인으로 예시를 들었다. doingSomeOperationGenerateSomeResult (어떤 동작을 하면 어떤 결과가 나온다.) someResultOccuersUnderSomeCondition (어떤 결과는 어떤 조건에서 발생한다.) Tip: 테스트하려는 맥락을 제안하기 보다는 어떤 맥락에서 일련의 행동을 호출했을 때 어떤 결과가 나오는지를 명시하는 것이 좋다고 한다. 위의 두가지는 좋다. 이것을 적용하면, 멋지지 않은 이름 멋진 이름 makeSingleWithdrawal withdrawalReducesBalanceByWithdrawnAmount attempToWith.. 2019. 9. 24.