Nodejs TCP socket, when ending, does not contain remoteAddress information

I am building a simple echo server for the purposes of learning the fundamentals about building tcp services with node.js and figuring out what information is available.

When I am creating a server, as shown below, I can access information about the incomingSocket such as the remote address. Why is it that I cannot access the information on the closing of socket? Below is my code; my comment indicates the output I have received.

var net = require ( 'net' );
var server = net.createServer (
    function ( incomingSocket )
    {
        //'connection' listener
        console.log ( 'Connection from ' + incomingSocket.remoteAddress + ':' + incomingSocket.remotePort + " established." );

        incomingSocket.on (
            'data' ,
            function ( data )
            {
                // The incomingSocket.remoteAddress is defined here
                console.log ( incomingSocket.remoteAddress + ':' + incomingSocket.remotePort + ' -> ' + data.toString () );
            }
        );

        incomingSocket.on (
            'close' ,
            function ()
            {
                // The incomingSocket.remoteAddress is undefined here
                console.log ( 'connection from ' + incomingSocket.remoteAddress + ' closed.' );
            }
        );
        incomingSocket.pipe ( incomingSocket );
    }
);
// listening to a port happens here

I would appreciate any response! Thank you!

Well no, because when it gets in the event handler for the socket close event, the socket object no longer exists. If you need to display the remote address of the client as the socket is closing, simply store the remote address as the client initially connects.

var clients = new Array();

net.createServer(function(socket) {
   var remoteAddress = socket.remoteAddress;
   var remotePort = socket.remotePort;

   // Add to array of clients
   clients.push(remoteAddress + ':' + remotePort);

   console.log('Connection from ' + remoteAddress  + ':' + remotePort + " established.");

   socket.on('data', function(data) {
      console.log(remoteAddress + ':' + remotePort + ' -> ' + data.toString());
   });

   socket.on('close', function() {
      // Remove from array of clients
      clients.splice(clients.indexOf(remoteAddress + ':' + remotePort), 1);

      console.log('Connection from ' + remoteAddress + ':' + remotePort + ' closed.');
   });

   ...