Unable to setRawMode in a nodejs script

4.7k views Asked by At

Initially I tried to set raw mode using tty.setRawMode(true) the log told me that was deprecated and I should be using process.stdin.setRawMode(true) but that command is giving me TypeError: Object #<Socket> has no method 'setRawMode' I cant seem to find much else in the way of raw mode documentation that suggests any other apporoaches anyone know how to get this working?

I am using version 0.10.25

2

There are 2 answers

0
Jake On

So it turns out nodemon uses child_process, because of this writing process.stdin.setRawMode(true); in a script that you then run with nodemon will result in TypeError: Object #<Socket> has no method 'setRawMode'.

0
Allen Highnote On

It works wonderfully via node server.js but nodemon server.js gives me TypeError: process.stdin.setRawMode is not a function error and the server aborts.

Since nodemon is also waiting for keys to be pressed (i.e. "rs" to restart server), we're running into a conflict because nodemon has commandeered process.stdin.

To workaround the issue, I added a config.ini directive named nodemonMode=yes|no. If it is set to yes, then I skip the offending section of code with the process.stdin.setRawMode(true) code in it. I bet there's is even a simpler way to determine if you're running nodemon.