title: How to allow CORS with Node.js (without using Express)
body: <p>I tried answers from other questions and used (updated from <a href="https://gist.github.com/balupton/3696140" rel="noreferrer">https://gist.github.com/balupton/3696140</a>):</p>
  
  <pre><code>var http = require('http');
  var cors = require('cors');
  
  http.createServer(app).listen(3000).use();
  
  function app(request, response) {
  
  response.setHeader('Access-Control-Allow-Origin', '*');
  response.setHeader('Access-Control-Request-Method', '*');
  response.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');
  response.setHeader('Access-Control-Allow-Headers', '*');
  
  ...
  
  }
  </code></pre>
  
  <p>It returns: <code>http.createServer(...).listen(...).use is not a function</code></p>
  
  <p>After the update it runs but I am still getting 405 error on the client side.</p>