E
E
Egor Telnov2019-08-14 12:12:31
Node.js
Egor Telnov, 2019-08-14 12:12:31

How to enable css?

Hello. I am learning to create simple http servers on Node. Faced a problem. Here is the code on the node:

app.get('/', (req, res) => {
    res.sendFile(__dirname + '/client/dist/index.html');
});

Everything is fine, index.html opens at this address. But on this page neither css nor js is connected. Where is the mistake?
<!DOCTYPE html>
<html lang="en">
<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">

    <link rel="stylesheet" href="./css/app.css">

    <title>Testing</title>
</head>
<body>
    <div class="container">
        <h1>Hello world!</h1>
    </div>
<script src = "./js/app.js"></script>
</body>
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Telnov, 2019-08-14
@telnov_magic

Issue resolved. If someone also faces such problem then here is expressjs.com/en/starter/static-files.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question