0

I am trying out the node.js keypress module to listen for keypress events. https://www.npmjs.com/package/keypress

I tried out the sample example.

var keypress = require('keypress');

// make `process.stdin` begin emitting "keypress" events 
keypress(process.stdin);

// listen for the "keypress" event 
process.stdin.on('keypress', function (ch, key) {
  console.log('got "keypress"', key);
  if (key && key.ctrl && key.name == 'c') {
    process.stdin.pause();
  }
});

process.stdin.setRawMode(true);
process.stdin.resume();

I would expect the sample code to work without error. However, I received an error

process.stdin.setRawMode(true);
              ^

TypeError: process.stdin.setRawMode is not a function

How to fix this error?

1 Answer 1

1

There is nothing wrong with the code. Perhaps you are trying to run the code in an IDE? Try running it from command-line;

$ node your_script.name.js
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.