ReferenceError: WebSocket is not defined

javascript, node.js, websocket

Solution

I think you're getting that line from this file, right? You're missing the line:

var WebSocket = require('ws')

which means you'll need to install `ws` with npm (`npm install ws`).

Problem

I am running my node js server which makes use of WebSocket but on execution it says "ReferenceError: WebSocket is not defined". I am new to to this and am unable to understand why this happening - how do I resolve this?

Original source