title: Handling Node.js socket data
body: <p>I have server receiving data from a client [GPS Device]. I have problem presenting the data (i.e the results obtained from the client) in a readable format. Below are the things I have tried.</p>
  
  <p>Doing:</p>
  
  <pre><code>console.log(data)
  </code></pre>
  
  <p>I get </p>
  
  <pre><code>&lt;Buffer d0 d7 3d 00 c4 56 7e 81&gt;
  </code></pre>
  
  <p>Also tried</p>
  
  <pre><code> console.log(data.toString())
  </code></pre>
  
  <p>But I get unwanted results:See below:</p>
  
  <pre><code>��A�V~�
  </code></pre>
  
  <p>Here is my full code:</p>
  
  <pre><code>var net = require('net');
  var fs = require('fs');
  
  var server = net.createServer(function (socket) {
    console.log('Server started: Waiting for client connection ...');
    console.log('Client connected:port,address: '+socket.remotePort,      socket.remoteAddress);
    socket.on('data', function (data) {
          var date = new Date();
          var today = date.getDate()+'_'+date.getMonth();
          fs.appendFile(today+'_log.txt', data, function (err) {
            if (err) throw err;
              console.log(data.toString())
  
      });
   });
  });
  
  server.listen(my_port, my_ip);
  </code></pre>
  
  <p>Thanks for your input.</p>