I just follow the tutorial in https://youtu.be/FduLSXEHLng?t=302, as below
const WebSocket = require("ws");
const wss = new WebSocket.Server({ port: 8082 });
wss.on("connection", ws => {
console.log("New client connected");
ws.on("close", () => {
console.log("Client has disconnected!")
})
})
When I run it with node index.js
, it seems to just end immediately (i.e. back to the prompt).
Anything wrong from my end? How can I check what terminate it? (or is it not terminated, but just the prompt showing?)
Sorry, I'm new to node.js and ws. Any guide on how can I debug from there will be great!
** Update **
After adding console.log("Hello");
const WebSocket = require("ws");
const wss = new WebSocket.Server({ port: 8082 });
console.log("Hello");
wss.on("connection", ws => {
console.log("New client connected");
ws.on("close", () => {
console.log("Client has disconnected!")
})
})
Then it seems to stay there.