Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

464
Views
socket.io "Cross-Origin request Blocked" error

So, I'm trying to follow along this tutorial and right off the bat I can't get it to work. First off, these are my files:

root/frontend/index.html

<html>
  [...]some static page[...]

  <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js"></script>
  <script src="index.js"></script>
</html>

root/frontend/index.js

const socket=io('http://localhost:3000');

socket.on('init', handleInit);

function handleInit(msg) {
   console.log(msg);
}

root/server/server.js

const io=require('socket.io')();

io.on('connection', client =>{
  client.emit('init', {data:'hello'});
});

io.listen(3000);

What he does next is running "npx live-server" in the frontend folder (which I also do). And also, run "yarn add socket.io" in the server folder and then run "npx nodemon server.js" and it's supposed to work. But doing those exact steps I get the errors: "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:3000/socket.io/?EIO=3&transport=polling&t=NsGvIgN. (Reason: CORS request did not succeed)"

and

"GET http://localhost:3000/socket.io/?EIO=3&transport=polling&t=NsGvO1Z"

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

So, I kinda figured it out.

In the end I end up following another tutorial which is much simpler and much better for the starter. It's this one. Easy to understand, to the point, compact and works with no issues.

But if you encounter this CORS error then the way to fix it is in another video. Basically you have to install the cors package and add some definitions in the server js code. The fix itself is in the 10 minute mark, but I suggest watching from the start.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!