Programming/node.js2020. 1. 29. 13:29

node.js 에서 사용할수 있는 라이브러리.

객체등을 uniq하게 정렬해줄수 있다는데

정작해보니.. 키에 따라서 정리만 해주는 정도?

 

[링크 : https://ddalpange.github.io/2017/10/10/js-not-duplicated-object-array/]

[링크 : http://underscorejs.org/]

[링크 : https://harrythegreat.tistory.com/entry/언더스코어-정리]

 

+

함수로 정리하는 내용

[링크 : https://gamblecoder.tistory.com/29]

 

'Programming > node.js' 카테고리의 다른 글

es6 전개문구 (...)  (0) 2020.01.29
node.js 객체 합치기  (0) 2020.01.29
node.js 집합연산  (0) 2020.01.23
node.js promise  (0) 2020.01.20
node.js cookie 관련 함수들  (0) 2020.01.19
Posted by 구차니
Programming/node.js2020. 1. 23. 19:32

array와 set을 통해서 집합 연산을 할 수 있다.

단.. 2개의 집합에 대해서는 용이한데 3개의 집합에 대한 교집합 은 쉽지 않고

객체에 대해서 하려면 이래저래 손이 많이 갈 듯..

 

3개의 집합에 대해서 항목별로 계산하려면

최소 7가지 정보가 필요한데

 

[링크 : https://zetawiki.com/wiki/JavaScript_합집합,_교집합,_차집합,_대칭차]

'Programming > node.js' 카테고리의 다른 글

node.js 객체 합치기  (0) 2020.01.29
unserscore 라이브러리  (0) 2020.01.29
node.js promise  (0) 2020.01.20
node.js cookie 관련 함수들  (0) 2020.01.19
node.js crypto 모듈  (0) 2020.01.19
Posted by 구차니
Programming/node.js2020. 1. 20. 16:10

promise는 비동기 작업을 동기작업으로 바꿀수(?)있는 마법의 키워드 이다.

아래와 같이 new promise를 통해서 만들어 주고

return new promise((resolve, reject) => {

// 비동기 작업

// 비동기 작업의 리턴값 (정상)

   resolve(value);

// 비동기 작업 비정상 종료시 리턴값

   reject(value);

})

 

3개의 비동기 작업이 모두 종료되고 그 값을 이용해 무언가를 하려면

promise.all로 구현을 해주고 값을 하나로 합쳐주면 된다.

Promise.all([worker1, worker2, worker3])

.then([value1, value2, value3]) => {

return ({value1, value2, value3})

 

 

[링크 : https://programmingsummaries.tistory.com/325]

[링크 : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Promise/all]

[링크 : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Promise]

 

구조 분해 할당

[링크 : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment]

'Programming > node.js' 카테고리의 다른 글

unserscore 라이브러리  (0) 2020.01.29
node.js 집합연산  (0) 2020.01.23
node.js cookie 관련 함수들  (0) 2020.01.19
node.js crypto 모듈  (0) 2020.01.19
node.js xpath 그리고 boolean  (0) 2019.12.17
Posted by 구차니
Programming/node.js2020. 1. 19. 17:17

쿠키를 삭제한다. 단 삭제만 하고 어떠한 응답을 주는것이 아니기에

redirection 등을 추가로 해주어야 클라이언트에서 작동을 인식한다.

res.clearCookie(name [, options])
Clears the cookie specified by name. For details about the options object, see res.cookie().

Web browsers and other compliant clients will only clear the cookie if the given options is identical to those given to res.cookie(), excluding expires and maxAge.

res.cookie('name', 'tobi', { path: '/admin' })
res.clearCookie('name', { path: '/admin' })

[링크 : https://expressjs.com/ko/api.html]

[링크 : https://victorydntmd.tistory.com/35]

 

 

아래 블로그의 path는 optional 이기에 굳이 넣어주지 않아도 된다.

app.get('/logout', function(req,res) {
    res.clearCookie(key);
});

 

app.get('/logout', function(req,res) {
    res.clearCookie(key, {path:'/path'});
});

[링크 : https://kwanghyuk.tistory.com/90]

'Programming > node.js' 카테고리의 다른 글

node.js 집합연산  (0) 2020.01.23
node.js promise  (0) 2020.01.20
node.js crypto 모듈  (0) 2020.01.19
node.js xpath 그리고 boolean  (0) 2019.12.17
node.js JWT with refresh token  (0) 2019.12.10
Posted by 구차니
Programming/node.js2020. 1. 19. 16:42

DB에서 하는거나 was에서 하는거랑 좀 차이가 있다면 있을수 있지만

postgresql의 경우 crypto 모듈을 설치해야 하는 문장 하나를 관리해줘야 하니

보안상 문제나 구조적 문제가 없다면 WAS에서 처리하는 것도 나쁘진 않다는 생각이 든다.

 

crypto 모듈은 기본 모듈이라 npm install을 해주지 않아도 된다.

const crypto = require('crypto');

const secret = 'abcdefg';
const hash = crypto.createHmac('sha256', secret)
                   .update('I love cupcakes')
                   .digest('hex');
console.log(hash);
// Prints:
//   c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e

 

[링크 : https://nodejs.org/api/crypto.html]

 

+

[링크 : https://victorydntmd.tistory.com/33]

'Programming > node.js' 카테고리의 다른 글

node.js promise  (0) 2020.01.20
node.js cookie 관련 함수들  (0) 2020.01.19
node.js xpath 그리고 boolean  (0) 2019.12.17
node.js JWT with refresh token  (0) 2019.12.10
node.js synchornous file write  (0) 2019.11.06
Posted by 구차니
Programming/node.js2019. 12. 17. 13:26

이제야 눈에 띄는 DOM3 XPath 1.0 implementation..

그래서 문법을 많이 적용 못 받은건가? 최신은 3.1인 것 같은데 1.0이라서 기능들이 많이 빠진듯

 

DOM 3 XPath 1.0 implemention and helper for JavaScript, with node.js support.

[링크 : https://www.npmjs.com/package/xpath]

 

아무튼 boolean() 함수는 결과값이 boolean 타입이다(당연하지만)

[링크 : https://developer.mozilla.org/ko/docs/Web/XPath/Functions/boolean]

 

아래는 xpath node.js npm의 예제를 이용하여

/book 노드가 실제로 존재하는지 boolean()으로 체크하도록 수정한 내용이다.

> var xpath = require('xpath')
undefined
>
> var dom = require('xmldom').DOMParser
undefined
> var xml = ""
undefined
> var doc = new dom().parseFromString(xml)
undefined
console.log(xml)

undefined
> var nodes = xpath.select("//title", doc)
undefined
console.log(nodes[0].localName + ": " + nodes[0].firstChild.data)
title: Harry Potter
undefined
var test = xpath.select("boolean(/book)", doc)
undefined
console.log(typeof test)
boolean
undefined
console.log(test)
true

typeof로 체크시 boolean 타입으로 나오니.. 기존에 프로그램을 좀 수정해야 할 듯..

'Programming > node.js' 카테고리의 다른 글

node.js cookie 관련 함수들  (0) 2020.01.19
node.js crypto 모듈  (0) 2020.01.19
node.js JWT with refresh token  (0) 2019.12.10
node.js synchornous file write  (0) 2019.11.06
postgres on node.js  (0) 2019.09.24
Posted by 구차니
Programming/node.js2019. 12. 10. 17:43

은행사이트 가면 10분 이내에 새로운 페이지 안가면 자동 로그아웃 되는데

이런식으로 token과 refresh token 두개를 이용해서 구현을 하는건가?

JWT가 어려운거냐.. 내가 머리가 안 좋은거냐..

 

[링크 : https://codeforgeek.com/refresh-token-jwt-nodejs-authentication/]

[링크 : https://solidgeargroup.com/refresh-token-with-jwt-authentication-node-js/]

'Programming > node.js' 카테고리의 다른 글

node.js crypto 모듈  (0) 2020.01.19
node.js xpath 그리고 boolean  (0) 2019.12.17
node.js synchornous file write  (0) 2019.11.06
postgres on node.js  (0) 2019.09.24
json2csv / node.js 에서 NULL 값 출력하기  (0) 2019.09.18
Posted by 구차니
Programming/node.js2019. 11. 6. 20:19

파일이 이상하게 저장되는 것 같아서 찾아보는데

결론만 말하자면.. 순차적으로 쓰는게 아니라 하나의 스트림을 여러군데에서 쓰면 문제의 소지가 있으니

synchronous로 쓰라인데.. 스트림 아웃이면 라인 단위로 되려나 어떻게 처리하게 되려나?

이런 부분을 좀 명확하게 찾아 봐야 할 듯.

 

[링크 : https://www.daveeddy.com/2013/03/26/synchronous-file-io-in-nodejs/]

[링크 : https://stackoverflow.com/...-write-to-append-to-the-same-file-guarantee-the-order-of-executio]

'Programming > node.js' 카테고리의 다른 글

node.js xpath 그리고 boolean  (0) 2019.12.17
node.js JWT with refresh token  (0) 2019.12.10
postgres on node.js  (0) 2019.09.24
json2csv / node.js 에서 NULL 값 출력하기  (0) 2019.09.18
js nested function과 변수 scope  (0) 2019.09.15
Posted by 구차니
Programming/node.js2019. 9. 24. 17:53

테스트용 was나 하나 짜볼까나...

 

[링크 : https://araikuma.tistory.com/459]

 

+ 2019.12.10

[링크 : https://node-postgres.com/]

'Programming > node.js' 카테고리의 다른 글

node.js JWT with refresh token  (0) 2019.12.10
node.js synchornous file write  (0) 2019.11.06
json2csv / node.js 에서 NULL 값 출력하기  (0) 2019.09.18
js nested function과 변수 scope  (0) 2019.09.15
node.js util.format / sprintf?  (0) 2019.09.10
Posted by 구차니
Programming/node.js2019. 9. 18. 19:29

value = undefined; 로 하면

csv 출력시 ,, 로 NULL 값으로 인식되도록 출력된다.

 

[링크 : https://www.npmjs.com/package/json2csv]

'Programming > node.js' 카테고리의 다른 글

node.js synchornous file write  (0) 2019.11.06
postgres on node.js  (0) 2019.09.24
js nested function과 변수 scope  (0) 2019.09.15
node.js util.format / sprintf?  (0) 2019.09.10
node.js xpath 지원함수 목록  (0) 2019.09.10
Posted by 구차니