Server/Node.js
서버에서 HTML 파일전송해보기
kkkkk1023
2023. 8. 22. 12:35
해당 글은 이전 글들의 작업을 이어서 진행되고 있는 글입니다.
1. 누군가 / 라는 경로로 방문을 하면 아래의 함수를 작동해라
app.get('/', function(request, response){
});
2. index.html라는 파일을 전송해라
app.get('/', function(request, response){
response.sendFile(__dirname + '/index.html');
});
이렇게 하고 http://localhost:8080 해당 url을 방문하면 미리 만들어진 html 파일을 보여준다.
[응용]
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h4>안녕하세요 홈페이지입니다.</h4>
<a href="http://localhost:8080/pet">펫</a>
<a href="http://localhost:8080/beauty">뷰티</a>
</body>
</html>