avatar
yeonwoo-log
express.js에서 css가 로딩이 안됨
Jul 6
·
1 min read

파일 경로

project {

back{

}

front {

main.html

script.js

style.css

}

node_modules {

. . .

}

package-lock.json

package.json

server.js

}

front/main.html

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>펜션 사이트</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    . . .
    <script src="script.js"></script>
</body>
</html>

server.js

const express = require('express')
const app = express()
const port = 8080
const path = require('path');

app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname, 'front', 'main.html'));
});

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})







𝑐𝑜𝑛𝑠𝑜𝑙𝑒.𝑙𝑜𝑔("𝐻𝑒𝑙𝑙𝑜 𝑤𝑜𝑟𝑙𝑑!")