npm install --save ws
or
- Inside your package.json using:
"dependencies": {
"ws": "*"
},
let ws = require('ws');
let WebSocket = require("ws");
let ws = new WebSocket("ws://host:8080/OptionalPathName);
Or
let WebSocketServer = require("ws").Server;
let ws = new WebSocketServer({port: 8080, path: "OptionalPathName"});
let WebSocketServer = require('ws').Server,
let wss = new WebSocketServer({ port: 8080 });
// If you want to add a path as well, use path: "PathName"
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received: %s', message);
});
ws.send('something');
});