Skip to content


 Zabbix
 Grafana
 Prometheus
 React Three Fiber
 Threejs and TypeScript
 SocketIO and TypeScript
 Blender Topological Earth
 Sweet Home 3D
 Design Patterns Python
 Design Patterns TypeScript
   
 Course Coupon Codes
Three.js and TypeScript
Kindle Edition
$6.99 $9.99 Paperback 
$22.99 $29.99




Design Patterns in TypeScript
Kindle Edition
$6.99 $9.99 Paperback
$11.99 $19.99




Design Patterns in Python
Kindle Edition
$6.99 $9.99 Paperback
$11.99 $19.99




Install Dependencies and Types

Video Lecture

Install Dependencies and Types Install Dependencies and Types

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, the code below has now been updated to support Socket.IO 4.5.1 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

npm install @types/node@16 --save-dev

Install SocketIO

npm install socket.io@4

Note

In the video I've installed the types @types/socket.io. This is no longer necessary since they now come included with the installation of socket.io instead.