Tuesday, 14 March 2017

Make favicon.ico appear at the top bar of the web page

I am using node.js to run the server. Always when I make a request to it actually there are occur two requests, one of which is an ordinary one, which was truly made and one is request/favicon.ico. So I tried to send favicon.ico back because I want it to appear in the top bar. But it just doesn`t appear there.

enter image description here

What am I doing wrong? Here is my code:

var http = require("http");

http.createServer(onRequest).listen(7777);
console.log("Server is running now.....");

function onRequest(request, response)
{
    console.log("A user made a request" + request.url);
    response.writeHead(200, {"Context-Type": "text/plain"});
    response.write("Here is some data");
    response.end();
}

And I put file favicon.ico into the same folder my server.js is.

enter image description here

This question:Set favicon in HTTP server? is not appropriate for me since the answer and code in answer, which were accepted for it don`t work for me.



via Yaroslav Trofimov

No comments:

Post a Comment