I have been trying with the following sample program?
var http = require("http");
var url = require('url');
var fs = require('fs');
var io = require('socket.io');
var server = http.createServer(function (request, response) {
console.log ("Connected..");
var path = url.parse (request.url).pathname;
console.log ("path is " + path);
switch (path) {
case '/':
response.write ("Hello.. use connectme.html ");
break;
case '/test':
console.log ("Hello insideo /test//");
response.write ("Hello. test..");
break;
case '/sock.html':
console.log ("sock.html..");
response.writeHead (200, {'Content-Type': 'text/html'});
fs.readFile(__dirname+path, function (error, data){
console.log ("Data is .. " + data);
response.writeHead(200, {'Content-Type': 'text/html'});
response.write(data, 'utf8');
});
break;
case '/index.html':
response.write ("Inside connect.em.html");
break;
default:
console.log (" Hell. i am not suppoed to be here...");
response.writeHead(404);
response.write("Unable to Find this page..");
break;
} // Switch
response.end();
});
server.listen(8765);
In Particular,
the below line doesn't seem to sending the html file from server to client:
console.log ("Data is .. " + data);
response.writeHead(200, {'Content-Type': 'text/html'});
response.write(data, 'utf8');
The HTML content is printed in the console. but in the browser nothing is displayed.
In sock.html, I just have one div with paragraph with dummy content.
I am sure i am doing some subtle error. Kindly Guide!!!.