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 -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -