Javascript/Node
[Node] Class 활용하여 express 선언하기
금요일인줄
2020. 10. 13. 12:39
728x90
반응형

'use strict'
const express = require('express')
const http = require('http')
// class로 express 선언
// http server를 확장
// 매우 중요 !
class ApiServer extends http.Server {
// singleton pattern 활용
// constructor를 통해서 클래스를 초기화하는데
// config를 통해 외부의 환경 설정을 읽어 옴
// 한 번만 config로 초기화 함
constructor (config) {
// express가 한 번만 생성되어 유일성을 보장받을 수 있음(중요!)
const app = express()
// super를 사용하여 해당 메소드를 다 사용 가능하게
super(app)
this.config = config
this.app = app
this.currentConns = new Set()
this.busy = new WeakSet()
this.stopping = false
}
async start() {
}
}
const init = async(config = {}) => {
const server = new ApiServer(config)
return server.start();
}

728x90
반응형