I am a beginner in node.js, I am learning it at w3schools.
Recently, when I was learning File System, I came accross fs.readFile method. As its first argument, I provided it with a link to a previously created html file. Now that file has a css stylesheet attached to it, whose href I edited (obviously). That marked the beginning of my problem.
After a lot of reading at several website and editing my code tons of times, this is the final version of my code.
My js, html and css are as follows -
var http = require('http'),
fs = require('fs'),
path = require('path'),
express = require('express'),
app = express();
app.use(express.static(path.join(__dirname, '/public')));
http.createServer(function (req, res) {
fs.readFile('.CSS Transitions - timing function.html', function (err, data) {
res.writeHead(200, {'Content-Type' : 'text/html'});
res.end(data);
});
}).listen(8080);
console.log('Server running at =>\n localhost:8080\nCtrl + C to quit');
a
{
transition : color 1s, font-size .5s;
transition-timing-function : ease;
color : black;
font-size : 30px;
}
a:hover
{
color : red;
font-size : 40px;
}
<!DOCTYPE html>
<html>
<head>
<title>Transition</title>
<link rel='stylesheet' type='text/css' href='css/CSS Transitions - timing function.css'>
</head>
<body>
<h2>Links</h2>
<ul>
<li><a href='http://www.htmldog.com'>HTML-Dog</a></li>
<li><a href='http://www.imdb.com'>IMDb</a></li>
<li><a href='http://www.youtube.com'>YouTube</a></li>
</ul>
</body>
</html>
The structure of my directory is
js file
html file
/public
/css
css file
PROBLEM >> No matter what I do, my css file isn't loading. This is the frequent error -
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:8080/css/CSS%20Transitions%20-%20timing%20function.css".
Don't know what to do anymore. I have been at it since 2 days, please HELP!!