ws-json adds a little abstraction to websocket

npm install ws-json
1 downloads in the last week
4 downloads in the last month

ws-json adds a little abstraction to websocket

JS prefers JSON-like objects while WebScokets uses strings,
I made this module to make WebSockets easier for JS.
Read ws-json-server for the server part.
Note that this is only a demo, it hasn't been tested.


Run npm install ws-json-client to install that.
This module is built based on Browserify, you need to note that.

delay = (t, f) -> setTimeout f, t

ws = require("../lib/index")
ws.connect "", 3000
ws.onopen -> console.log "opened"
ws.on "greet", (data) ->
  console.log data

ws.on "delay", (data) ->
  console.log "delay", data

console.log "start"
delay 1000, ->
  ws.emit "call", "from client"

ws.on "repeat", (data) ->
  ws.emit "repeat", data
  console.log "have data", data


  • ws.connect: accepts hostname and port

If you only pass a port, the hostname name will be localtion.hostname

  • ws.onopen ->: accepts a callback as a parameter

  • ws.on: accepts a key and a callback function

  • ws.emit: accepts a key and a value


I use node-dev to debug this module

npm loves you