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?

1

2 Answers 2

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)

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.