X
X
xymox722018-06-15 03:55:23
Node.js
xymox72, 2018-06-15 03:55:23

Why is Node Express not serving JS?

Simple code:
in server.js

app.use('*/styles', express.static('./public/styles'));
app.use('*/js', express.static('./public/js'));

app.get('/', (req, res) => res.sendFile(__dirname + `/public/main.html`));

in html:
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="/styles/style.css">
    <title></title>
</head>
<body>
    <div id="app">
     <h1>Типо страница</h1>
    </div>
<sciprt src="/js/test.js"></script>
</body>
</html>

But when visiting the localhost:3000 page, the page is loaded with css, but the js file does not even try to load.
5b230dd2b3320172653903.jpeg
While typing into the address bar localhost:3000/js/test.js outputs the js file.
5b230dfe462f3484090648.jpeg
CHADNT?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question