JPuge JPuge - 1 year ago 105
Node.js Question

Detect enter in keypress event node.js rawmode

I am writing a simple commandline tool to allow commandline input to a node.js server.
I am trying to make a buffer, so the user can press up and see the last command. To do that I have set


And detects all keypress with:

process.stdin.on('keypress', function (letter, key) {
if (key && key.ctrl && == 'c') {
} else if (key && key.enter) {

bufferPos += 1;
buffer[bufferPos] = "";
} else {
buffer[bufferPos] += letter;

This does not detect enter-presses.

Are there a way to detect when a whole line is fires (as when RawMode is false) alongside with the keypress event? If not, how I detect the enter-press?


As far as I can see, your only error is that this:

else if (key && key.enter) {

should be this:

else if (key && == 'enter') {