1

I am trying to create a simple node js server that print 'new client' when any one open the server URL. This is my code

var http = require('http');
var server = http.createServer();
server.on('request', function(req, res){
    res.end('hello world');
    console.log('new client');
});

server.listen(8080);

but when i open the http://localhost:8080 the console output 'new client' two times, it should be one line, is this normal?

Karim Harazin
  • 1,463
  • 2
  • 16
  • 34
  • Possible duplicate of [Node.js double console.log output](http://stackoverflow.com/questions/17952436/node-js-double-console-log-output) – RBT May 21 '17 at 02:30

2 Answers2

4

This is normal your browser makes more than one call. Every browser make a call to grab /favicon.icon.

Try to console the url and you'll see:

console.log(req.url)

Raghavan
  • 883
  • 1
  • 8
  • 19
2

I've had similar experiences with nodejs.

I think it's normal if you are using the chrome browser. Since chrome does some extra requests.

Check here. Chrome - multiple requests

Community
  • 1
  • 1