import express, { Request, Response } from "express"; import * as http from 'http'; import WebSocket from "ws" const app = express(); const server = http.createServer(app); const ws = new WebSocket.Server({server}) ws.on("connection", (ws : WebSocket)=>{ ws.on("message", (message : string)=>{ console.log('received: %s', message); ws.send(`Hello, you sent -> ${message}`); }) ws.send('Hi there, I am a WebSocket server'); }) app.get("/", (req: Request, res: Response) => { res.send("Hello World"); }); const port = process.env.PORT || 5000 server.listen(port, () => { console.log(`Server started on port ${port} :)`); })