Piping text between processes in node?

I'm connecting to a remote server via ssh (via a child process) and so I want to see the output of this in the terminal, then when I exit the server I get back to my node program. It's working except once I connect to the server anything I enter via the terminal gets duplicated. I assume this is because I am displaying the original process.stdin.pipe along with the ssh.stdin. How can I prevent this? The code is below, along with an example of a simple ls from within the server

var connect = function(callback) {
  ssh.stdout.pipe(process.stdout, { end: false });
  process.stdin.resume();

  process.stdin.pipe(ssh.stdin, { end: false });

  ssh.on('exit', function () {
    callback();
  });
}; 


ubuntu@ip-xxxx:~$ llss

test.html
ubuntu@ip-xxxx:~$

To do this you want to take full control over the input using Readline:

http://nodejs.org/docs/latest/api/readline.html