bookmark_borderSocket.IO

Socket.IO is a library that enables real-time, bidirectional, and event-based communication between the browser and the server.

Socket.io

https://socket.io/docs/v3/index.html

Server

ECMAScript

import * as socket from "socket.io";
const io = new socket.Server()

CommonJs

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

With Express, migrating from 2.x to 3.x

Socket.IO compatibility

Socket.IO’s .listen() method takes an http.Server instance as an argument. As of 3.x, the return value of express() is not an http.Server instance. (See the Application function section above.) To get Socket.IO working with Express 3.x, make sure you manually create and pass your http.Server instance to Socket.IO’s .listen() method.

var app = express()
  , http = require('http')
  , server = http.createServer(app)
  , io = require('socket.io').listen(server);
server.listen(3000);




ANOTE.DEV