728x90
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel = "stylesheet" href="/css/index.css">
<script src="/js/index.js"></script>
</head>
<body>
<div id="main">
반갑습니다.
</div>
</body>
</html>
const express = require("express");
const socket = require("socket.io");
const http = require("http");
//Node.js 기본 내장 모듈 로딩****************
const fs = require("fs") //FileSystem 모듈
//******************************************
const app = express();
const server = http.createServer(app);
const io = socket(server);
app.use("/css", express.static("./static/css"));
app.use("/js", express.static("./static/js"));
app.get("/", function(req, res){
console.log("유저가 /로 접속함");
fs.readFile("./static/index_1.html", function(error, data){
if(error){
res.send("에러 발생")
} else {
res.writeHead(200, {"Content-Type": "text/html"});
res.write(data);
res.end();
}
});
});
//서버 8081포트로 listen
server.listen(8081, function(){
console.log("서버 실행중...");
});
'단순 코드 기록 > Node' 카테고리의 다른 글
Node_소켓을 통한 채팅 (0) | 2024.03.27 |
---|---|
Node_소켓통신 적용 (0) | 2024.03.27 |
Node_소켓통신을 이용한 서버 가동 (0) | 2024.03.27 |
Node_Template 사용 + Update (0) | 2024.03.26 |
Node_pathVariable_Delete (0) | 2024.03.26 |