Started building the Webserver
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
26
src/app.ts
26
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");
|
||||
Reference in New Issue
Block a user