앞서 했던 것은 텍스트를 전송했었는데(express 라이브러리 사용해서)
const express = require("express");
const app = express();
app.listen(8080, function(){
console.log("listening on 8080");
});
app.get("/pet", function(req,res){
res.send("펫용품 파는 곳이다");
});
HTML파일을 전송할 수도 있다.
("/") 는 홈 의 의미인 페이지인데, 홈 접속시 HTML파일을 보내주고 싶다면
이번엔 send가 아닌 sendFile 을 사용해준다.
sendFile(__dirname + "HTML파일");
const express = require("express");
const app = express();
app.listen(8080, function(){
console.log("listening on 8080");
});
app.get("/", function(req,res){
sendFile(__dirname + "HTML파일");
});
그러면 작성해놓은 HTML파일이 / 경로에 접속시 나타나는 것을 볼 수 있다.