max-mapper / websocket-stream

websockets with the node stream API
BSD 2-Clause "Simplified" License
668 stars 114 forks source link

Add an example of express-js #130

Closed moshest closed 7 years ago

moshest commented 7 years ago

Using express-ws module:

const express = require('express');
const expressWebSocket = require('express-ws');
const websocketStream = require('websocket-stream/stream');
const app = express();

// extend express app with app.ws()
expressWebSocket(app, null, {
    perMessageDeflate: false,
});

app.ws('/bigdata.json', function(ws, req) {
  const stream = websocketStream(ws, {
    binary: true,
  });

  fs.createReadStream('bigdata.json').pipe(stream);
});

app.listen(3000);
mcollina commented 7 years ago

Can you send us a PR?

moshest commented 7 years ago

Please see #132.