본문 바로가기

분류 전체보기49

[NodeJs] 모듈 사용 2023. 9. 8.
API Application Programming Interface 응용프로그램에서 사용할 수 있도록, 운영 체제나 프로그래밍 언어가 제공하는 기능을 제어할 수 있게 만든 인터페이스를 뜻한다. 주로 파일 제어, 창 제어, 화상 처리, 문자 제어 등을 위한 인터페이스를 제공한다. Client [1] Server [2] Database [1] : resquest, response [2] : query, query result [1]의 과정을 API 호출이라고 한다. [1]이 언제 이뤄지는 지 모른다! => 그렇기 때문에 비동기 호출인 Promise 객체를 이용한다. async function getData() { let rawResponse = await fetch("https://jsonplaceholder.ty.. 2023. 9. 8.
async / await function hello(){ return 'hello'; } async function helloAsync(){ return "hello Async"; } console.log(hello()); console.log(helloAsync().then((res)=>{ console.log(res); })); async function : 비동기 함수를 선언 해줌으로써 반환 값은 Promise로 받는다. 따라서 "hello Async"라는 콘솔을 보기 위해서는 then이나 catch를 사용해야 한다. 2023. 9. 8.
promise pending -> fulfillled : resolve pending -> rejected : reject 콜백 지옥 function taskA(a,b,cb){ setTimeout(()=>{ const res = a + b; cb(res); },3000) } function taskB(a,cb){ setTimeout(()=>{ const res = a * 2; cb(res); },1000) } function taskC(a,cb){ setTimeout(()=>{ const res = a * -1; cb(res); },2000) } taskA(3,4,(a_res)=>{ console.log(a_res); taskB(a_res,(b_res)=>{ console.log(b_res); taskC(b_res,(.. 2023. 9. 7.