node.js - Counting visitors in a node http server -


my source code:

 var http = require("http");  var count=1;   http.createserver(function(request, response) {  response.writehead(200, {"content-type": "text/plain"});      response.write("hi, number "+count+" visitors");  response.end();  count++;   }).listen(8888);   

i got 1,3,5,7,..... in each visit. why increment count 2?

the request favicon.ico triggering request (i confirmed logging details each request , making normal request chrome).

you need explicitly type of request (url, method, etc) you're wanting match.

also, keep in mind, if server dies, @ stage, count reset. if don't want that, should persist somewhere less volatile, such database.


Comments

Popular posts from this blog

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -