Install Dependencies and Types
Video Lecture
Description
Create Socket Server Script, Install Dependencies and Types
src/server/server.ts
Note
In the video, my server.ts
is using Socket.IO 2.3.0
, it now uses Socket.IO 3.0.4
which means that line 14 has now been updated from
const io = socketIO(this.server)
to
const io = new socketIO.Server(this.server);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import http from "http" import socketIO from "socket.io" const port: number = 3000 class App { private server: http.Server private port: number constructor(port: number) { this.port = port this.server = new http.Server(); const io = new socketIO.Server(this.server) } public Start() { this.server.listen(this.port, () => { console.log( `Server listening on port ${this.port}.` ) }) } } new App(port).Start() |
Install Dependencies and Types
Install Types for Nodejs
1 | npm install @types/node |
Install SocketIO
1 | npm install socket.io |
Install Types for SocketIO
1 | npm install @types/socket.io |