The TCP chat program in nodejs asks for help?

  node.js, question

In the for statement of the following code, when I open two clients, the message sent by one client can be received as soon as it is output by USERS [I]. Why can’t the message be received when it is output by conn.write, and it is clearly a for loop, shouldn’t the message be output twice in a row?

var net=require('net');
 
 var count=0,users={};
 var server=net.createServer(function(conn){
 conn.setEncoding('utf-8');
 var nickname;
 conn.write(
 '\n > welcome to node-chat!'
 Add' \n >' add count and 'other people are connected at this time.'
 Add' \ n > please write your name and pressenter:'
 );
 Count plus;
 conn.on('data',function(data){
 data=data.replace('\r\n','');
 if(!  nickname){
 if(users[data]){
 conn.write('>nickname already in use,try again:');
 return;
 }else{
 nickname=data;
 users[nickname]=conn;
 for(var i in users){
 **users[i].write ('>' plus nickname plus' joined the room\n');  **
 bracket
 bracket
 bracket
 });
 conn.on('close',function(){
 count--;
 });
 });
 
 server.listen(3000,function(){
 console.log('server listening on *:3000');
 });

In the user object, the user’s nickname is used as the key to maintain the connection it holds.
If there are n users, there will be n userKey, corresponding to n tcp connections at the same time.
The message broadcast must be sent through the conn corresponding to the user before the client can receive it.

for(var userKey in users){
 Conn.write ('>' plus nickName plus' joined the room\n');
 bracket

This conn is the TCP connection of the user currently triggering the data event, conn.write is to send a message to himself ~ ~ ~ ~

for(var userKey in users){
 Users[userKey].write ('>' plus nickName plus' joined the room\n');
 bracket

Traverse users, and take out the corresponding TCP connection, send a message ~ ~

In addition:
The code can be optimized. nickName is useless ~ ~ ~

var nickName=data.replace('\r\n','');
 if(users[nickName]){
 conn.write('>nickname already in use,try again:');
 return;
 }else{
 users[nickName]=conn;
 for(var userKey in users){
 Users[userKey].write ('>' plus nickName plus' joined the room\n');
 bracket
 bracket