4

I wanna build a view counter functionality for my website just like here on stackoverflow view counter: View counter functionality in stackoverflow I know how to build that, each time a user hit the post url, increment its view times by one. But the problem is that a user can come and refresh the page as much as he wants. How to fix that? any suggestion? I will be really glad if you can tell me the algorithm or code of that.

Joseph
  • 1,676
  • 2
  • 10
  • 20

1 Answers1

-1

You can customize this code to your POST function << Good lock (:

var http = require('http');

var userCount = 0;
var server = http.createServer(function (req, res) {

userCount++;
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('Hello!\n');
res.write('We have had ' + userCount + ' visits!\n');
res.end();
});

server.listen(9090);
console.log('server Up and running... 9090');
Mohsen
  • 11
  • 7