Skip to content

Node.js

james2doyle edited this page Sep 12, 2014 · 2 revisions

The websocketd works with line-breaks. String.trim() will fix that for you, but don't forget to end with a line-break when sending data.

script.js

// Start listening
process.stdin.resume()
process.stdin.setEncoding('utf8')

// Receive data from WebSocket - STDIN
process.stdin.on( 'data', function( data ) {

  // Send data to WebSocket client - STDOUT
  process.stdout.write( JSON.stringify({ text: data.trim() }) +'\n' )

})
websocketd nodejs script.js
Clone this wiki locally