title: I'm unable to figure out how to prevent getting this CORS error in Node.js
body: <p>I'm trying to figure out how to create a real time chat application that uses Vue.js for the front-end, Node.js for the back-end and socket.io.</p>
  
  <p>I've generated my back-end Node.js project with express-generator and the project is accessible at <a href="http://localhost:3000" rel="nofollow noreferrer">http://localhost:3000</a>. In this project I have an app.js file that contains this:</p>
  
  <pre><code>var express = require('express');
  var http = require('http').createServer(express);
  var io = require('socket.io')(http);
  
  io.on('connection', (socket) =&gt; {
      console.log('a user connected');
  });
  </code></pre>
  
  <p>My front-end is a Vue.js project accessible from <a href="http://localhost:8080" rel="nofollow noreferrer">http://localhost:8080</a> and the component that is meant to connect to my back-end contains this:</p>
  
  <pre><code>&lt;template&gt;
      &lt;div class="home"&gt;
  
      &lt;/div&gt;
  &lt;/template&gt;
  
  &lt;script&gt;
  import socket from 'socket.io-client'
  
  export default {
      mounted(){
          socket.connect('http://localhost:3000')
      }
  }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Sadly the socket connection doesn't seem to go through. On the front-end console I get these errors - </p>
  
  <pre><code>localhost/:1 Access to XMLHttpRequest at 'http://localhost:3000/socket.io/?EIO=3&amp;transport=polling&amp;t=N6Kc6yn' from origin 'http://localhost:8080' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
  </code></pre>
  
  <p>And on the back-end console I get this error - <code>GET /socket.io/?EIO=3&amp;transport=polling&amp;t=N6KcMan 404 3.089 ms - 975</code></p>
  
  <p>I tried installing cors through npm install cors and added the required code but nothing really happened. It looks like this:</p>
  
  <pre><code>var express = require('express');
  var cors = require('cors');
  var app = express();
  app.use(cors());
  
  var http = require('http').createServer(express);
  var io = require('socket.io')(http);
  
  io.on('connection', (socket) =&gt; {
      console.log('A user has connected!');
  });
  </code></pre>
  
  <p>I can't figure out why is this happening.</p>