Today, We want to share with you Nodejs Real time online users counter using socket io Example.In this post we will show you Showing online users using Nodejs and Socket.io, hear for Node JS – Get Real time online users counter using socket io example we will give you demo and example for implement.In this post, we will learn about Real time online activity monitor example with node.js and WebSocket with an example.
Nodejs Real time online users counter using socket io Example
There are the Following The simple About Nodejs Real time online users counter using socket io Example Full Information With Example and source code.
first of all You have latest verison installed nodejs, express as well as new socket.io package using npm, As I will cover this Post with live Working example to develop count online users on my website in real time with node.js, so the some major files and Directory structures for this example is following below Steps for real time chat with nodejs socket io and expressjs.
- index.html
- server.js
Nodejs Real time online users counter
index.html
This is where I will make a simple HTML form and Node JS server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.html.
Real time online activity monitor example with node.js and WebSocket socket NodeJS Live Conter :
socket io real time online users example
Step 2 : Node JS server.js
server.js
Simple Nodejs Real time online users counter for server.js files
var liveapp = require('express')(); var server = require('http').Server(liveapp); //node js active users counter var io = require('socket.io')(server); //nodejs socket.io online users counter server.listen(8001); var flags = 0; var $ipsConnected = []; io.on('connection', function (socket) { var $liveIpAddress = socket.handshake.address; //check socket io online users if (!$ipsConnected.hasOwnProperty($liveIpAddress)) { $ipsConnected[$liveIpAddress] = 1; flags++; //socket io real time online users example socket.emit('socket_io_counter', {flags:flags}); } console.log("Good Luck, client is connected"); /* Your Live (socket.io client flags) Disconnect socket */ socket.on('disconnect', function() { if ($ipsConnected.hasOwnProperty($liveIpAddress)) { delete $ipsConnected[$liveIpAddress]; flags--; socket.emit('socket_io_counter', {flags:flags}); } }); });
Save And run server.js file
run Project and Nodejs Get Real time online users counter using socket io Example
//Nodejs Real time online users counter nodejs server.js
Nodejs Real time online users counter using socket io – Output
Angular 6 CRUD Operations Application Tutorials
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about Nodejs Real time online users counter using socket io Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.