Alex O'Connor
Alex O'Connor

Reputation: 152

Node.js resouce not found 404 HTML

I am attempting to add node.js to my webpage project. I have working .html, .js, and .css files. I then added a node.js file, and ran it with node node.js and the .html loads, but I get, in firefox:

The resource from “http://localhost:2020/path/to/public/website.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).

How do I get the .css and .js files to import properly? (If I just open the .html, the files are correct.

testFunction = function() {
    alert("I work!");
}
* {
    background-color: rgb(51, 45, 45);
    color: rgb(163, 149, 149);
    font-family: cursive;
    font-size: larger;
}

h1 {
    text-align: center;
}
<!DOCTYPE html>
<html>

<head>
    <title>Index</title>
    <link rel="stylesheet" type="text/css" href="./website.css">
</head>

<body>
    <h1>Thanks for looking at me</h1>
    <p><span id="story">This is a story</span></p>
    <button onclick="testFunction()">This is a useless button</button>
    <script type="text/javascript" src="./site.js"></script>
</body>

</html>

var io = require('socket.io');
var url = require('url');
var express = require('express');
var http = require('http');
var app = express();
var server = http.createServer(app);
var socket = io.listen(server);

app.engine('.html', require('ejs').__express);
app.set('views', __dirname + '/public');
    app.set('view engine', 'html');

app.get('/', function(req, res) {
    res.sendFile(__dirname + '/public/index.html');
});

app.listen(2020);

Upvotes: 0

Views: 24

Answers (1)

farvilain
farvilain

Reputation: 2562

Seems yo have no route to serve css/js with express. . Here is a doc to serve static files with express

Upvotes: 1

Related Questions