Node Question Js Fevicon.ico?

I am new to NodeJs and started doing this http://danielnill.com/nodejs-tutorial-with-socketio/ tutorial for node js, but when I click the url it automatically asks for "fevico.ico" and also doesn’t display required html page content. I tried shorting the request to "fevico.ico", but it doesn’t work, and I don’t have tools to debug the js code on the server side, so it’s very frustrating to solve this problem below, this is my code and a screenshot from the console log screen.

My server.js file code

  var http=require("http");
  var url=require('url');
  var fs=require('fs');

  var server = http.createServer(function(request, response){
console.log('Connection');
var path = url.parse(request.url).pathname;
console.log(path);
switch(path)
{
    case '/':
        response.writeHead(200,{'Content-Type':'text/html'});
        response.write('heloo world');
        break;
    case '/socket.html':
        fs.readFile(__dirname+path,function(error,data){
        console.log(data.toString());
            if(error!=null)
            {
                response.writeHead(404,{'Content-Type':'text/html'});
                response.write('oops this does not exist - 404');
            }
            else
            {
                response.writeHead(200,{'Content-Type':'text/html'});
                response.write(data,"utf8");
            }
        });
        break;
    case '/favicon.ico':
        response.writeHead(200, {'Content-Type': 'image/x-icon'} );
        console.log('favicon requested');
        break;
    default:
        break;
}
response.end();
});
server.listen(8001);

and my console screen looks like

enter image description here

, socket.html, response.write fevico.ico. - ? .

+4

Source: https://habr.com/ru/post/1539271/


All Articles