A process in nodejs automatically repeat for infinite time

Posted May 15, 2017 3.5k views
Node.jsArch Linux

When i start a index.js file through command line

node index.js

It starts but, it print the result multiple time even a single user is connected.
Result is:-

7544816137 is connected
connected as id 277
7544816137 is connected
connected as id 277

This happens on digital ocean server only, It doesn’t happen on localserver.
Please tell me a way to resolve this problem

  • @sheshant
    Friend provide more info, How the client is connecting? Post more logs? Show us the source code?

  • Client side code

    var socket;
    var n='sheshant';
     socket = io("http://hostip:4000",{query:'name='+n});
          socket.on('chatmsg', function(msg){
          var user = JSON.parse(msg);
          if(user.type=="user") {
            $("#msg_console").append("<div id='out_name'>""</div>"+"<div id='out_msg'>"+user.message+"<br>"+"<div class='downtimer'>"+user.time+"<br>";   
          } else {
                $("#msg_console").append("<div id='sys_msg'>"+user.message);

    Server side code

    var app = require('express')();
    var http = require('http').Server(app);
    var io = require('')(http);
    var date = require('date-and-time');
    var mysql = require('mysql');
    var pool      =    mysql.createPool({
        connectionLimit : 100, //important
        host     : 'localhost',
        user     : 'root',
        password : '',
        database : 'db',
        debug    :  false
    io.on('connection', function(socket){
        var store;
         console.log(store+" is connected");
    console.log(" is connected");
    socket.on('disconnect', function(){
         console.log(store+" is disconnected");
    console.log(" is disconnected");
    http.listen(4000, function(){
      console.log('listening on *:4000');
Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!