title: node 7.6 async await issues with returning data
body: <p>I am working on a simple TCP client for a server and am using the latest node 7.6 because of the async/await functions. I'm new to node and asynchronous coding, so I apologize if this is stupidly easy.</p>
  
  <p>I want to run a function that calls the callServer() function with specific parameters, wait until it finishes getting the data, and return the data as a variable.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>'use strict'
  const net = require('net')
  
  var formattedJson = funcRequestToJson("Server.GetStatus", false)
  
  doThings()
  
  async function doThings() {
      var info = await callServer()
  }
  
  async function callServer() {
      var client = new net.Socket()
  
      client.connect(1705, '192.168.28.16', () =&gt; {
          console.log('connected to server')
          client.write(formattedJson)
      })
  
      client.on('data', (data) =&gt; {
          client.destroy()
          //return await data
          console.log(data.toString())
      })
  
      client.on('close', () =&gt; {
      })
  }
  
  // method and paramBool are always required
  // macAddress, paramKey, paramValue are required for if paramBool is true
  function funcRequestToJson(method, paramBool, macAddress, paramKey, paramValue) {
      var objectRequest = {}
  
      objectRequest[ "jsonrpc" ] = "2.0"
      objectRequest[ "method" ] = method
      objectRequest[ "id" ] = 0
      if (paramBool == true) {
          objectRequest[ "params" ] = {
              "client": macAddress,
              [paramKey]: paramValue
          }
      }
  
      var json = (JSON.stringify(objectRequest) + '\r\n')
  
      return json
  }
  </code></pre>
  
  <p>So I didn't declare objectRequest() as async because it's not waiting on the server, but I think callServer() should be async, right? I know this can be done with promises, but I wanted to use async/await and this seems to be right.</p>
  
  <p>Now, I want to return the data that comes from inside callServer() and client.on('data', (data) but I can't seem to figure out how to do it asynchronously. I would think there'd be a way to make an async function and call it with await like I tried (await return data) but it never works right.</p>
  
  <p>I'm sorry if this is terribly convoluted, but I've been poring over async node tutorials for the past week and am still stuck.</p>
  
  <p>Thanks!</p>