title: Socket.io No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access
body: <p>I'm trying to learn nodejs with socket.io and at the moment I'm using <a href="https://github.com/GianlucaGuarini/nodejs-MySQL-push-notifications-demo" rel="noreferrer">this tutorial by GianlucaGuarini</a>. When entering my client.html file I get the following error. I know what it means and that it´s there for preventing Cross browser scripts but I don´t know how to allow my nodejs script to access the client.html file.   </p>
  
  <pre><code>XMLHttpRequest cannot load http://localhost:8000/socket.io/?EIO=3&amp;transport=polling&amp;t=1422653081432-10. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
  </code></pre>
  
  <p>Here is a part of my code with socket.</p>
  
  <pre><code>  var app = require('http').createServer(handler),
    io = require('socket.io').listen(app),
    fs = require('fs'),
    mysql = require('mysql'),
    connectionsArray = [],
    connection = mysql.createConnection({
      host: 'localhost',
      user: 'root',
      password: '',
      database: 'database',
      port: 3306
    }),
    POLLING_INTERVAL = 3000,
    pollingTimer;
  
  // If there is an error connecting to the database
  connection.connect(function(err) {
    // connected! (unless `err` is set)
    console.log(err);
  });
  
  // creating the server ( localhost:8000 )
  app.listen(8000);
  
  // on server started we can load our client.html page
  function handler(req, res) {
  
    res.writeHead(200, {
        /// ...
        'Access-Control-Allow-Origin' : '*'
    });
  
    fs.readFile(__dirname + '/client.html', function(err, data) {
      if (err) {
        console.log(err);
        res.writeHead(500);
        return res.end('Error loading client.html');
      }
      res.writeHead(200);
      res.end(data);
    });
  }
  </code></pre>
  
  <p>Does anyone know how I can solve my problem?</p>
  
  <p>Kind regard / H</p>