A
A
Alexander Degtyarev2017-01-06 01:52:29
JavaScript
Alexander Degtyarev, 2017-01-06 01:52:29

Why is the TTY module needed in nodejs?

I read the documentation and did not understand why it is needed? After all, there are readline and REPL modules? Please tell me or give a description. Thank you in advance)))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2017-01-06
@bingo347

In essence, the following happens inside the node:

const tty = require('tty');
if(tty.isatty(0)) {
  process.stdin = new tty.ReadStream();
} else {
  //init process.stdin from other stream
}

var outStream;
if(tty.isatty(1)) {
  outStream = new tty.WriteStream();
  process.stdout = outStream;
} else {
  //init process.stdout from other stream
}
if(tty.isatty(2)) {
  if(!outStream) {
    outStream = new tty.WriteStream();
  }
  process.stderr = outStream;
} else {
  //init process.stderr from other stream
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question