Node.js
비동기
이벤트 기반
(event-driven) JavaScript runtime
환경
Runtime describes software/instructions that are executed while your program is running, especially those instructions that you did not write explicitly, but are necessary for the proper execution of your code.
Low-level languages like C have very small (if any) runtime. More complex languages like Objective-C, which allows for dynamic message passing, have a much more extensive runtime.
You are correct that runtime code is library code, but library code is a more general term, describing the code produced by any library. Runtime code is specifically the code required to implement the features of the language itself.
- 프로그램의
기능
혹은함수
들이 서로 방해(blocking) 하지 않고 동시에 일어날 수 있음- 역할의 분리가 핵심
- 함수를 비동기로 실행하기 위해서
javascript
에서는promise
라는 개념을 이용- 함수는
Promise() 객체
를 return(반환)해줘야 한다- promise 는 인자로,
-resolve
,reject
두가지를 객체로 받는다
- Promise((resolve, reject) =>
- Single Thread 의 역할은 카페 종업원
- Internal C++ thread pool은 각각의
callback - > 함수의 인자로 함수를 사용하는 것
# es5 까지의 문법
# callback 지옥의 예
fetch('BACKEND_API', (res) => {
fetch('BACKEND_API', (res) => {
fetch('BACKEND_API', (res) => {
})
})
})
# 가독성과 유지보수 차원에서 어려운 callback지옥
=> callback(함수)으로 처리하던 비동기 작업을 handling하기 위해서 promise라는 개념이 생김!
JavaScript 런타임(runtime) 환경
Node.js에서 비동기로 처리해 줘야 할 대표적인 작업!
js에서 this는 python에서 self와 같은 역할이다
MVC (Model View Controller)
View -(Request)-> Controller
View <-(Response)- Contoller
ex)
django-views.py - 컨트롤러 역할, 유저의 요청을 제어하는 곳
urls.py 가 따로 존재하는 이유?
API의 module화 하기 위해서! -> 코드간의 의존성을 낮춤
Backend
Route
Controller
Service
Model
아래(하위) layer
에만 의존함!!JS에서 함수는 일급객체
(first-class-citizen)
일급객체
(first-class-citizen)