Started building the Webserver

This commit is contained in:
2025-05-05 23:21:32 +02:00
parent 994b0c938e
commit a30556aadc
2 changed files with 30 additions and 2 deletions

View File

@@ -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"
}
}

View File

@@ -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");