NodeJS HTTP Server和Console.log

时间:2021-05-30 16:57:28

I have a simple HTTP server

我有一个简单的HTTP服务器

require('http').createServer(function(req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World!');

    console.log('Got a request');   
}).listen(4000);

However, when I run it 'Got a request' is written 3 times in the console. Any idea why?

但是,当我运行它时,“有一个请求”会在控制台中写入3次。知道为什么吗?

1 个解决方案

#1


2  

It's maybe your browser who try to get your favicon

也许是您的浏览器试图获取您的图标

You can confirm this by using : console.log('Got a request : ' + req.url);

您可以使用以下命令确认:console.log('有一个请求:'+ req.url);

#1


2  

It's maybe your browser who try to get your favicon

也许是您的浏览器试图获取您的图标

You can confirm this by using : console.log('Got a request : ' + req.url);

您可以使用以下命令确认:console.log('有一个请求:'+ req.url);