title: http.createServer on('request') async/await functions
body: <p>Trying to use an async function in request event from node.js http.createServer. I want to use vanilla node.js modules.
  I know I can use external dependencies but wish to solve without ideally.</p>
  
  <p>I can't understand why I am getting the data back from async function as seen from console.logs yet the curl resp doesn't include it. I am not getting any errors, like writing headers after resp was sent back so confused why curl doesn't have body of <code>{ data: 1 }</code>. If I remove async/await and hardcode the req.end to be 'test' its returned in curl request.</p>
  
  <p><strong>server.js</strong></p>
  
  <pre><code>const server = http.createServer();
  server.on('request', async (req, res) =&gt; {
    const data = await someAsyncFunc();
    console.log(req.url);
    console.log(data);
    res.end(JSON.stringify(data));
  });
  </code></pre>
  
  <p><strong>terminal</strong></p>
  
  <pre><code>curl localhost:3000/test -v
  *   Trying 127.0.0.1...
  * TCP_NODELAY set
  * Connected to localhost (127.0.0.1) port 3000 (#0)
  &gt; GET /test HTTP/1.1
  &gt; Host: localhost:3000
  &gt; User-Agent: curl/7.54.0
  &gt; Accept: */*
  &gt;
  &lt; HTTP/1.1 404 Not Found
  &lt; Content-Type: text/plain; charset=utf-8
  &lt; Content-Length: 9
  &lt; Date: Tue, 17 Apr 2018 18:44:00 GMT
  &lt; Connection: keep-alive
  &lt;
  * Connection #0 to host localhost left intact
  Not Found%
  </code></pre>
  
  <p><strong>server.js log</strong></p>
  
  <pre><code>/test
  { data: 1 }
  </code></pre>
  
  <p>----- <strong>UPDATE</strong> ------</p>
  
  <p>Seems like the cause of this issue is I'm passing in a koa app.callback() to createServer, that seems to break the async stuff some how in request event for http server:</p>
  
  <pre><code>const app = new Koa();
  http.createServer(app.callback());
  </code></pre>
  
  <p>I would have prefered to use server.on('request') but the only way I can get this to work is to use koa middleware.</p>