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/Java2020. 1. 15. 13:01

개념은 대충 알았지만.. 시대가 바뀌어서 그런가..

예전의 맨날 돌리고 돌리는 orbit 보다는 구체화된 예로 이해하기가 쉬운 시대가 되었네.

 

[링크 : https://gmlwjd9405.github.io/2018/07/05/oop-features.html]

[링크 : https://gmlwjd9405.github.io/2018/07/05/oop-solid.html]

'Programming > Java' 카테고리의 다른 글

java 람다, 클로저  (0) 2025.01.31
자바 annotation  (0) 2020.06.16
java cipher  (0) 2019.11.25
jaxb - Java Architecture for XML Binding  (0) 2019.06.25
jar 실행하기  (0) 2019.01.15
Posted by 구차니
Programming/jsp2020. 1. 15. 12:31

java/tomcat 으로 서버 호스팅 하는데도 많으니

정적웹을 java/tomcat으로 war 파일을 통해 deploy 가능하겠다 싶어서 검색

 

[링크 : https://10apps.tistory.com/118]

Posted by 구차니
Programming/Java(Spring)2020. 1. 15. 10:50

JDK 설치

$ sudo apt install openjdk-8-jdk

[링크 : https://daddyprogrammer.org/post/2062/openjdk-install-update-delete/]

 

예제 spring 프로젝트 다운로드(git)

$ git clone https://github.com/spring-guides/gs-rest-service.git

$ cd gs-rest-service/initial

$ ./gradlew bootRun

[링크 : https://spring.io/guides/gs/rest-service/]

 

http://localhost:8080/greeting

외부에서 접근하려면 ip로 바꾸고 8080 포트로 접속하면 된다.

다만.. 위에서 bootRun으로 했기 수정없이 실행했기에 greeting이 아직 생성되지 않아 접근이 되지 않는다.

gs-rest-service/initial/src/main/java/com/example/restservice/Greeting.java

package com.example.restservice;

public class Greeting {

private final long id;
private final String content;

public Greeting(long id, String content) {
this.id = id;
this.content = content;
}

public long getId() {
return id;
}

public String getContent() {
return content;
}
}

 

gs-rest-service/initial/src/main/java/com/example/restservice/GreetingController.java

package com.example.restservice;

import java.util.concurrent.atomic.AtomicLong;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();

@GetMapping("/greeting")
public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
return new Greeting(counter.incrementAndGet(), String.format(template, name));
}
}

+

위에서 GetMapping으로 greeting일 경우에

Parameter 이기에 greeting?name= 형식으로 값을 받되, 값이 없으면 기본값을 World로 지정해 주는 것으로 보인다.

@로 시작하는 annotation들은 조금 공부가 필요 할 듯 하다.

 

 

이렇게 파일 두개 추가해주고 gs-rest-service/initial 디렉토리로 돌아와

gradlew bootRun을 실행후

http://localhost:8080/greeting

http://localhost:8080/greeting?name=User

을 접속하면 15분(?) 강좌 끝

 

+

gradlwe bootRun은

gradle 도움말에 안나오는 걸 봐서는 spring boot 에서 추가된 taskName으로 추정된다.

[링크 : https://docs.gradle.org/current/userguide/command_line_interface.html]

 

+

[링크 : https://spring.io/guides/gs/spring-boot/] spring boot

[링크 : https://spring.io/guides/gs/accessing-data-rest/] JPA

[링크 : https://spring.io/guides/gs/accessing-data-mysql/] MYSQL

Posted by 구차니

dictionary 라고 하는 녀석은 node.js 에서 json 객체와 같은 녀석으로 보이는데..

아무튼 dictionary라고 하니 그렇게 표현을 해주자 -_-

 

dictionary는 {}

list는 []

tuple은 () 으로 표기되며

 

dictionary와 tuple은 [0]을 통해서 접근이 가능하고

dictionary는 ['apple'] 식으로 접근방법이 추가된다.

 

list는 []로 접근할 수 없으며, append(), pop() 등을 통해 stack이나 queue로 사용이 가능하다.

대신 list 답게 정렬등의 기능을 지원한다.

'Programming > python(파이썬)' 카테고리의 다른 글

pythonpath  (0) 2021.04.16
python yield  (0) 2021.04.07
python 반복문 for in range()  (0) 2020.01.11
python print 와 while 문  (0) 2020.01.11
오랫만에 한가로움?  (0) 2020.01.11
Posted by 구차니
Programming/Java(Spring)2020. 1. 13. 14:37

java VM 특성(?)으로 localhost에 대해서 주소를 IPv4와 IPv6로 resolve하는 것으로 보인다.

java -jar 앞에 아래의 옵션을 주면 해결!

 

-Djava.net.preferIPv4Stack=true

[링크 : https://hane-1.tistory.com/42]

'Programming > Java(Spring)' 카테고리의 다른 글

ckedtior file upload  (0) 2024.02.07
spring 다시 시작  (0) 2020.01.15
jsoup html body 사이즈 제한  (0) 2019.09.26
java 메모리 관련...2?  (0) 2019.07.06
java.lang.OutOfMemoryError: GC overhead limit exceeded  (1) 2019.07.06
Posted by 구차니

왜 열거형(sequence)를 따라서 for문을 사용하게 했는지 모르겠지만..

일단은 열거형은 []로 나열되는 tuple의 list 혹은 array라고 하는데

node.js와 비교하면 배열을 foreach 로 반복하도록 문법을 제한한 느낌이라고 해야하나?

 

[링크 : https://www.w3schools.com/python/ref_func_range.asp]

[링크 : https://www.learnpython.org/en/Loops]

'Programming > python(파이썬)' 카테고리의 다른 글

python yield  (0) 2021.04.07
python 공부  (0) 2020.01.14
python print 와 while 문  (0) 2020.01.11
오랫만에 한가로움?  (0) 2020.01.11
python split  (0) 2020.01.10
Posted by 구차니

 

if guess == number:
    print('same')
elif guess < number:
    print('larger then')
else:
    print('lesser then')

 

node.js와는 다르게 문자열과 숫자를 마음대로 + 로 출력할 수가 없다.

그리고 while 문에 대해서도 특이하게 else가 붙어서 마지막 조건에서 벗어날때 무언가를 할 수 있다.

(무슨 용도로 이걸 만들었을까..)

cnt = 10;

while cnt > 0:

cnt = cnt - 1;

print('cnt:', cnt);

else:

print('cnt <= a', cnt);

 

[링크 : https://www.opentutorials.org/module/2980/17535]

'Programming > python(파이썬)' 카테고리의 다른 글

python 공부  (0) 2020.01.14
python 반복문 for in range()  (0) 2020.01.11
오랫만에 한가로움?  (0) 2020.01.11
python split  (0) 2020.01.10
python 겅부  (0) 2020.01.09
Posted by 구차니