In your web request handler, at the end, do response.end() right outside of your switch block.
Edit: You have to do it at the end of each write, because you are doing asynchronous file reading. If you use readFileSync, you could write it once at the end.
http://nodejs.org/api/http.html#http_response_end_data_encoding
So your file would look like like:
var url = require("url");
var fs = require("fs");
function handle(request, response){
var pathname = url.parse(request.url).pathname;
console.log(pathname);
switch(pathname){
case '/':
fs.readFile("../html/index.html", function(error, data){
if(error){
response.writeHead(404);
response.write("This file does not exist.");
response.end();
}
else{
response.writeHead(200, {"Content-Type": "text/html"});
response.write(data, "utf8");
response.end();
}
});
break;
default:
fs.readFile("../html" + pathname, function(error, data){
if(error){
response.writeHead(404, {"Content-Type": "text/html"});
response.write("<html><body>This file does not exist!</body></html>");
response.end();
console.log("Test");
}
else{
response.writeHead(200, {"Content-Type": "text/html"});
response.write(data, "utf8");
response.end();
}
});
}
}
exports.handle = handle;
Note that response.end('foo'); is equivalent to response.write('foo'); response.end();
Also, I know this is a bit off topic, but you should try out the express framework for node. It makes a lot of web request handling easy without being overly opinionated.