title: How to create TCP client in NodeJS using async/await?
body: <p>I have written the following <code>tcp client</code> in nodejs.</p>
  
  <pre><code>const net = require('net');
  
  const HOST = 'linux345';
  const PORT = 2345;
  let ErrCode = 1;
  
  const client = new net.Socket();
  
  client.connect(PORT, HOST, function() {
      ErrCode = 0;
  });
  
  client.on('data', function(data) {    
      console.log('Client received: ' + data);
       if (data.toString().endsWith('exit')) {
         client.destroy();
      }
  });
  
  client.on('close', function() {
  });
  
  client.on('error', function(err) {
      ErrCode = err.code;
      console.log(ErrCode);
  });
  
  console.log(ErrCode);
  </code></pre>
  
  <p>Please suggest how can I write same logic using async/await</p>
  
  <p>I have looked into the following post but it is not helpful.
  <a href="https://stackoverflow.com/questions/42440537/node-7-6-async-await-issues-with-returning-data">node 7.6 async await issues with returning data</a></p>