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

257
Views
NodeJs - Socket.io, Can't access socket.io.js trough js file

I want to access socket.io.js trough an external js file (in my case called script.js), but I am getting the following error when trying to access trough the client side js file.

Uncaught ReferenceError: io is not defined

But when using js inside of my html it works fine. My Node.js API serves socket.io.js correctly and is accessable. Following html code works without errors.

<script src="/socket.io/socket.io.js"></script>
    <script>
        const socket = io();
        socket.on('message', function (message) {
        console.log(message);
        });

    </script>
</script>

While external js code doesn't work

const socket = io();
socket.on('message', function (message) {
console.log(message);
});

All js file are linked in head of my html

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

0

I'm kinda dump found my mistake called my script.js in header before socket.io.js

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!