누군가 우리 주소에 방문했을 때 HTML파일을 보내는 코드를 작성해보자
작성해본 server.js파일과 같은 경로에 index.html
파일 생성 후 작성
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h4>홈페이지 첫 작성 해봤어</h4>
</body>
</html>
위처럼 작성 후 다시 server.js
에 아래처럼 작성해보자
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html')
})
너무 간단하고 쉽노