Instale o soquete.io
npm i socket.io
hateschoollovecoding
npm i socket.io
<script src="https://cdn.socket.io/socket.io-3.0.1.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
const socket = io();
</script>
const server = require('http').createServer();
const io = require('socket.io')(server);
io.on('connection', client => {
client.on('event', data => { /* … */ });
client.on('disconnect', () => { /* … */ });
});
server.listen(3000);
npm install --save socket.io
It is a library that enables real-time, bidirectional and event-based communication between the browser and the server.