Connect a Socket.io stream to node repl stream

i created a express app with socket.io. Now i want a browser terminal to be connected with the repl I created in node. Here is what i came up with

var io = io.listen(server);
var sessionSockets = new SessionSockets(io, sessionStore, cookieParser);

sessionSockets.on('connection', function (err, socket, session) {
  var stream = createStream(socket);
  var replInstance = repl.start({
    prompt: "> ",
    input: stream,
    output: stream
  });
  repls[socket.id] = replInstance;
});

var createStream = function(socket) {
  var stream = new Stream();
  stream.readable = true;
  stream.resume = function() {};

  stream.write = function(data) {
    socket.emit('stdout', data);
  };

  socket.on('stdin', function(data) {
    // emit data to repl stream - DOES NOT WORK
    stream.emit('data', data);
  });

  return stream;
};

What it does already is pushing the console outputs to the socket.io connection and displays them in the frontend. What it does not is entering data from the frontend in the repl.

Ideas?

I just tried your code, and I think you might need a line break on your stream emit for repl to recognize it:

// emit data to repl stream - DOES NOT WORK
stream.emit('data', data+'\n');