I am using node.js and trying send the .html file contains these tags:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="This is my personal profile website" />
<link rel="stylesheet" type="text/css" href="profile_design.css" />
<link rel="stylesheet" href="jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<script type="text/javascript" src="profile.js"></script>
Here is the HTTP server in node.js :
var fs = require('fs');
var http = require ('http');
http.createServer(function (request, response) {
console.log('request starting...');
fs.readFile('C:/Users/.../index.html', function(error, content) {
if (error) {
response.writeHead(500);
response.end();
} else {
//response.writeHead(200, { 'Content-Type': 'text/html' });
response.end(content, 'utf-8');
}
console.log(error);
});
}).listen(8080);
The problem is that the index.html file is return in good manner but all the JavaScript files and the CSS are not sent correctly to the client side. The question is how to send those .js and .css files?
The browser tries to get the .css and .js resource files via port 8080, thorugh your node.js server. However, your server won’t serv any of them but the index.html file irrespectively of the request.
Advice: Use the express.js plugin and set up a bit more complex routing.