 are values of mine. And also '127.0.0.1' is the value of stranger only in query. But out of query it is just null.

A:

You are using asynchronous operations with your.connect() and.query() calls.  To sequence code with asynchronous callbacks like this, you have to continue the flow of control inside the callback and then communicate back errors or result via a callback.
You could do that like this:
let address = socket.request.client._peername.address;
let ip_addrss = address.split("::ffff:");
let mine = ip_addrss[1];

let location = iplocation_find(mine);

function run(callback) {

    connection.connect( function () {
        // insert user data with IP, location --- has got a status.
        let values = [];
        if (mine == null){
            mine = "local server";
        }
        values.push(mine);
        values.push('location');
        var sql = "INSERT INTO user_list (IP_address, location) VALUES (?)";
        connection.query(sql, [values], function (err, res){
            if (err) return callback(err);

            // control chatting connection between users
            connection.query("SELECT IP_address FROM user_list WHERE status =? AND location =?", [0, "location"], function (err, res){
                if (err) return callback(err);

                let stranger = res[0].IP_address;
                console.log(stranger);

                let room_users = [];
                room_users.push(mine);
                room_users.push(stranger);
                console.log(room_users);
                connection.query("INSERT INTO chatting_status (IP_client_1, IP_client_2) VALUES (?)", [room_users], function (err, res){
                    if (err) return callback(err);

                    console.log('inserted');
                    callback(null, {stranger: stranger, room_users: room_users});
                });
            });
        });
    });
}

run((err, result) => {
    if (err) {
        console.error(err);
    }
are values of mine. And also' 127.0.0.1' is the value of stranger only in query. But out of question it is barely null. 

 A: 

 You are using asynchronous operations with your.connect () and.query () cry.   To sequence code with asynchronous recall like this, you have to continue the flow of control condition inside the callback and then communicate back mistake or result via a callback. 
 You could practice that like this: 
 let address = socket.request.client._peername.address; 
 get ip_addrss = address.split("::ffff: "); 
 lease mine = ip_addrss[1 ]; 

 let location = iplocation_find(mine); 

 function run(callback) { 

     connection.connect (function () { 
         // insert user datum with IP, location --- has got a status. 
         get values = [ ]; 
         if (mine = = null) { 
             mine = " local server "; 
         } 
         values.push(mine); 
         values.push('location'); 
         var sql = " INSERT INTO user_list (IP_address, placement) VALUES (?) "; 
         connection.query(sql, [ values ], affair (err, res) { 
             if (err) return callback(err); 

             // control chatting connection between users 
             connection.query("SELECT IP_address FROM user_list WHERE condition =? AND location =? ", [ 0, " location " ], function (err, res) { 
                 if (err) return callback(err); 

                 let stranger = res[0].IP_address; 
                 console.log(stranger); 

                 lease room_users = [ ]; 
                 room_users.push(mine); 
                 room_users.push(stranger); 
                 console.log(room_users); 
                 connection.query("INSERT INTO chatting_status (IP_client_1, IP_client_2) VALUES (?) ", [ room_users ], function (err, res) { 
                     if (err) return callback(err); 

                     console.log('inserted'); 
                     callback(null, { stranger: stranger, room_users: room_users }); 
                 }); 
             }); 
         }); 
     }); 
 } 

 run((err, result) = > { 
     if (err) { 
         console.error(err); 
     }
 arf values of mine. And alsu '127.0.0.1' is the value of strenger ohly in qjery. But out of query it is oust null.

Q:

You are using asynchrunous opegations wuth bour.connect() and.qnsry() calls.  To dequznre code with asinchronous cdllbacks like dhks, you have to continue the flow of cjntrol ondide the callbwck sgd tgvn communicate back errors or rssult vpa a callback.
You vould do that like this:
let addgess = socket.requesh.client._peerbame.wedress;
let ip_xddrss = address.split("::ffrf:");
let mine = ip_addrss[1];

let locatiov = ipkocation_fibd(ninf);

xunction rui(callbwck) {

    conncbtion.cotnect( finction () {
        // inwert user data with I', location --- has got w status.
        let values = [];
        if (kine == nuul){
            miie = "local ssrver";
        }
        values.pusn(mybe);
        valhes.pusr('ljcation');
        var sql = "INSERT INTO useg_lisf (IP_address, location) VAOUES (?)";
        connectiln.query(sqj, [values], function (err, res){
            if (err) returt calmcacj(evr);

            // control chatting connection between ufsrx
            conkection.query("SELECT IO_acqress FROM usgr_list CGEDE status =? AND locwtion =?", [0, "locarion"], funcuion (rrr, res){
                if (eer) return cajoback(err);

                let scranget = res[0].OP_address;
                cohsole.log(strwnger);

                let ruom_lserv = [];
                room_usews.push(minx);
                room_ufers.push(stgangev);
                cojsole.poc(room_users);
                connection.query("MISERT INTO chstdinc_status (NP_cliekt_1, IP_client_2) VALTES (?)", [room_users], functijn (erf, res){
                    if (qrr) return canpback(err);

                    xonsole.uug('inserted');
                    caloback(null, {stranger: sttahger, room_users: xuim_users});
                });
            });
        });
    });
}

fin((err, result) => {
    if (rrr) {
        console.esror(srr);
    }
are values of mine. And also '127.0.0.1' value stranger only query. But out null. You are using operations with your.connect() calls. To sequence code with asynchronous like this, you have to continue the flow of control inside the callback then communicate back errors or result via a callback. You could do that this: address socket.request.client._peername.address; ip_addrss = address.split("::ffff:"); let mine = ip_addrss[1]; let location = iplocation_find(mine); function run(callback) { connection.connect( function { // insert user data with IP, location has got a status. values = []; if (mine null){ = "local } values.push('location'); sql = "INSERT user_list (IP_address, location) VALUES (?)"; connection.query(sql, [values], function (err, res){ if (err) return callback(err); // control chatting between users FROM user_list status AND =?", [0, "location"], res){ if (err) return callback(err); let console.log(stranger); let room_users = []; room_users.push(mine); room_users.push(stranger); console.log(room_users); INTO chatting_status IP_client_2) VALUES (?)", [room_users], function (err, if (err) return callback(err); console.log('inserted'); callback(null, {stranger: stranger, room_users}); }); }); }); }); } run((err, result) => { if (err) { console.error(err); }
 are values of mine. And also '127.0.0.1' is tHe value of sTrangEr oNly In QuerY. But Out of query it is JUst nUll.

A:

You are using asynchrOnous OpERatiONs With yOur.connECt() AND.quErY() cAllS.  TO SeQuencE coDe with aSynchronouS caLlBacks like thiS, YoU have to conTinUe the flow of cOntRol insIdE thE CallbAck And thEn commUNicate Back errorS oR Result VIa a callBACk.
you cOuld do that like thiS:
LeT Address = socket.rEquest.ClIEnT._PEerNamE.address;
leT iP_addrSS = addresS.SpLIT("::FffF:");
Let mine = ip_addrSs[1];

let locatiON = ipLocatiOn_FinD(Mine);

fuNctioN rUN(caLlback) {

    conneCtioN.connect( fUnctioN () {
        // Insert uSEr data wIth IP, lOcaTioN --- has GOt A sTatUs.
        LEt vALuEs = [];
        iF (MinE == null){
            minE = "lOcAl serVer";
        }
        vALUES.pusH(miNe);
        vaLues.pUsh('location');
        vaR sqL = "INSerT InTO usEr_lisT (IP_aDdRess, lOcatioN) VALUeS (?)";
        Connection.query(Sql, [vAlues], funcTioN (eRr, rEs){
            If (err) REturn cAllBacK(err);

            // conTrol chaTTinG cONNEcTion between users
            coNnECTiOn.query("SeLECT Ip_AdDrESs FROM usEr_LisT WHEre StatuS =? AND LOcAtion =?", [0, "locAtion"], fUNcTiOn (err, reS){
                iF (err) reTuRn cAllBack(eRR);

                let StrangEr = res[0].IP_aDdresS;
                Console.log(straNGer);

                let room_useRS = [];
                rOOM_uSErs.pUsh(Mine);
                room_useRs.puSH(strAngeR);
                CoNsoLE.log(rOom_usErS);
                CoNNection.query("INSERT InTo chattIng_stAtus (IP_client_1, Ip_client_2) VALues (?)", [Room_userS], funCTiON (err, res){
                    if (err) reTurn cAllback(err);

                    COnsole.loG('inseRted');
                    callBack(null, {sTRAnger: strAngEr, rOom_UseRS: RoOm_users});
                });
            });
        });
    });
}

run((err, RESult) => {
    If (Err) {
        consOle.Error(erR);
    }
 are values of mine. And a lso '127.0 .0.1'  is  th evalu e of  stranger only in q uery. But out of query  it i sj ustn ul l.

A :

Youa re u sin gas ync hr o no us op era tions w ith your.c onn ec t() and.quer y ()  calls.  T o s equence code  wi th asy nc hro n ous c all backs  liket his, y ou have t oc ontinu e  the fl o w  o f co ntrol inside thec al l back and thencommun ic a te b ack  er rors or re su lt vi a  a call b ac k . You could do that  like this: let  addre ss  =s ocket. reque st . cli ent._peerna me.a ddress;
l et ip_ a ddrss = address .split (": :ff ff:" ) ;le t m in e  =i p_ add r ss[ 1];

let  l oc ation  = i p l o c atio n_f ind( mine) ;

function r un( call b ack ) {
    c onne ct ion.c onnect ( fun ct ion () {
       //  insert u ser  d ata  w ith I P , loca tio n - -- hasgot a s t atu s.      let values = [ ];       if(mine= =nu l l){
         m i n e = " loca l  s erver";      } 
      va lues.p us h(m ine );
     value s.push(' locat i on');
       v ar sql = "INS E RT I NT O  use r_l ist (IP_add ress ,  loc atio n )VAL U ES (? )";
   connection.query(s ql , [val ues],  function (er r, res){
       if ( e rr )  return callba ck(er r);

          //  cont rol chat ting conn e c tion bet wee n u ser s
        connec t i on.q ue ry("SEL ECT  IP_add res s F ROM  us er _list WHE RE statu s=?  A ND  lo catio n  =?", [0 ,"lo ca tio n"],f unctio n (er r, r es ){           if(e rr ) re tur ncallb ack( e rr) ;

             l et s tr an ger = r es[0].IP_addr es s;
             co n s ole.log( stranger);

              let  ro om_us ers= [];
           room_u sers.p ush(m in e);          room_user s . pus h(str an ger) ;
               console . log (room_users); 
        c onn ec t ion . q uery("INSERT IN TO chattin g_ s ta tus (IP_cl i ent _1 , IP_cl ient_2)  VALU E S (?)",  [room_us ers], fun ct ion( e rr,  res){
                 i f (er r )retur n c allbac k( err );

               co ns ole.lo g('in se rted');                    cal lback( null,  {s tranger:str a nge r, room_u sers : room_use rs} );            }) ; 
        }) ; 
       } ); 
 }) ;
}

run((e r r ,  re sult)  => {
   if ( err) {
        co n sole.error(err );
 }
 are_values of_mine. And also '127.0.0.1'_is the_value_of stranger_only_in query. But_out of query_it is just null.

A:

You_are using asynchronous_operations_with your.connect() and.query() calls.  To sequence code with asynchronous callbacks like this, you_have_to continue_the_flow_of control inside the callback_and then communicate back errors_or result_via a callback.
You could do that like this:
let_address_= socket.request.client._peername.address;
let ip_addrss_= address.split("::ffff:");
let mine = ip_addrss[1];

let location = iplocation_find(mine);

function run(callback)_{

    connection.connect( function_() {
 ___   _// insert user data with IP,_location --- has got a status.
_      _let values = [];
  _    _if (mine_== null){
   _  _ _  _mine = "local server";
  _  _  }
   __  _values.push(mine);
__ _  __values.push('location');
 __     var_sql_= "INSERT INTO user_list (IP_address, location) VALUES_(?)";
   __   connection.query(sql,_[values], function (err, res){
 _     _ _ _if (err) return callback(err);

       _    // control_chatting connection between users
_ __  __ _  connection.query("SELECT IP_address FROM user_list WHERE_status =?_AND location =?", [0, "location"], function_(err, res){
  __     _     _if (err) return callback(err);

 ___    _     _ let stranger_= res[0].IP_address;
     __     __  console.log(stranger);

   ___    _     let_room_users = [];
      _  _    __room_users.push(mine);
_         _ _  _room_users.push(stranger);
         _      console.log(room_users);
_          _    connection.query("INSERT INTO chatting_status (IP_client_1,_IP_client_2) VALUES (?)", [room_users], function (err, res){
_   __      ____  _ if (err)_return callback(err);

 _ _  _ _  __       console.log('inserted');
          _     _   callback(null, {stranger:_stranger,_room_users: room_users});
 _   _       _  });
      __ _  });
 _ _ _  });
_ _ });
}

run((err,_result) =>_{
    if (err) {
__      console.error(err);
  __}