'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
Solution 1:[1]
I'm kinda dump found my mistake called my script.js in header before socket.io.js
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | xpz |
