node.js - WebSocket on node js server (ReferenceError) -
according npm docs :
ws simple use, blazing fast, , thoroughly tested websocket client , server implementation.
so have installed it
npm install ws
and tried little test on node js file :
const websocket = require('ws'); const ws = new websocket('ws://www.host.com/path');
but receive error :
referenceerror : websocket not defined
what doing wrong please ?
edit :
it typing error.
i used
const websocket = require('ws'); const ws = new websocket('ws://www.host.com/path');
but have use :
const websocket = require('ws'); // websocket camelcase... const ws = new websocket('ws://www.host.com/path');
your using client logic on server, try
const websocket = require('ws').server; const ws = new websocket({ port: 8080 });
Comments
Post a Comment