私は完全なノード初心者で、問題に直面しています:
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('Connection');
var path = url.parse(request.url).pathname;
switch(path){
case '/':
response.writeHead(200, {'Content-Type': 'text/html'});
response.write('Hello World');
break;
case '/socket.html':
fs.readFile(__dirname + path, function(error, data){
if (error){
response.writeHead(404);
response.write("This doesn't exist - 404");
console.log(error);
} else {
console.log('hi!'); // **************<---- I'm getting here
response.writeHead(404, {'Content-Type': 'text/html'});
response.write(data, 'utf8');
}
});
break;
default:
response.writeHead(404);
response.write("This page does not exist - 404");
console.log(path);
break;
}
response.end();
});
server.listen(8001);
io.listen(server);
「else」内で console.log() に到達していますが、response.write は何も出力しません。console.log(data) を取得すると、