Express는 node.js 진영에서 가장 대표적인 웹 프레임워크 중 하나이다. 다른 웹 프레임워크도 많이 존재하지만 Express가 가장 많이 사용된다. Express 사용법을 잘 숙지한 상태라면 다른 웹 프레임워크를 사용할 때에도 쉽게 적응할 수 있다. Express는 웹 어플리케이션을 미니멀하고 유연하게 만들 수 있도록 도와준다.
npm install express
npm install --save-dev @types/express
타입 도움을 받기 위해 설치한다.
const express = require('express')
const app = express() // 앱 생성
const PORT = 5000
app.use('/', (req, res) => {
res.send('Hello, express!')
})
// 포트 설정
app.listen(PORT, () => {
console.log(`The Express server is listening at port: ${PORT}`)
})
express에서 제공하는 함수를 사용해서 쉽게 서버를 구현할 수 있다.