Reputation: 21
I am making a chat app using socket.io. According to the website documentation, i have to provide a javascript file source which is:
<script src="/socket.io/socket.io.js"></script>
whereas my socket.io folder is under node_modules and on the other hand socket.io folder doesn't even contain socket.io.js, socket-client folder does. I have tried other docs but cannot find any explanation. Can anyone please explain how its working correctly even with the wrong path.
Upvotes: 2
Views: 1017
Reputation: 2161
When you instantiate a socket.io
server, it serves the client file at the /socket.io/socket.io.js
address automatically without you having to provide anything.
You can thus choose whether you want to import the io
from this file, or from the socket.io-client module.
<script src="/socket.io/socket.io.js"></script>
<script>
const socket = io();
</script>
const io = require('socket.io-client');
// or with import syntax
import io from 'socket.io-client';
const socket = io();
Upvotes: 3