diff --git a/package.json b/package.json index ac8d063..3aa668f 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,14 @@ }, "license": "MIT", "author": "Zacharias", - "type": "module", + "type": "commonjs", "main": "./build/app.js", "scripts": { "start": "node build/app.js", "test": "echo \"Error: no test specified\" && exit 1" + }, + "dependencies": { + "@types/ws": "^8.18.1", + "ws": "^8.18.2" } } diff --git a/src/app.ts b/src/app.ts index accefce..dcb6e1e 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1 +1,25 @@ -console.log("Hello World"); +import WebSocket, {WebSocketServer} from "ws" + +const wss = new WebSocketServer({ + port: 8080, + +}) + +wss.on("connection", (ws) => { + console.log("Connection connected"); + + ws.on("message", (data) => { + console.log(data); + ws.send(data); + }); + + ws.on("close", () => { + console.log("Connection closed"); + }); + + ws.on("error", (err) => { + console.error(err); + }); +}); + +console.log("Server started"); \ No newline at end of file