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 mand 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
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 mand 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
Share Improve this question asked Jun 19, 2015 at 19:50 JakeJake 6291 gold badge7 silver badges14 bronze badges 8- 2 Check the result of process.stdin.isTTY. If it is false, node is not running in a TTY context and process.stdin will not be a TTY.readStream – Dylan MacKenzie Commented Jun 19, 2015 at 19:55
-
To find out why this is, I need more information on how you are running your program. Are you using
child_process
perhaps? – Dylan MacKenzie Commented Jun 19, 2015 at 19:57 -
How would I go about checking that? I ran it with no result and
console.log
returns undefined. No child process. – Jake Commented Jun 19, 2015 at 20:00 - Let me rephrase: when you execute node, are you running a script or using the repl? Are you on Windows or Linux? Any information would help (console.log always returns undefined). Node is likely unable to detect that it is being run from a terminal, so I need more information about your environment to help. – Dylan MacKenzie Commented Jun 19, 2015 at 20:04
-
I meant I ran
console.log(process.stdin.isTTY)
and got undefined. Am running linux no repl, am running it through terminal withnode myscript.js
stdout.write
works fine so standard in/out seems to be the console. – Jake Commented Jun 19, 2015 at 20:09
2 Answers
Reset to default 5It 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 mandeered 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.
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'
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744173087a4561628.html
评论列表(0条)