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

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -