Tuesday 2 October 2018

node.js: Readline: close method

rl.close()
This method closes the readline.Interface instance and relinquishes control over the input and output streams. This method emits the close event.

HelloWorld.js
/* Import readline module */
var readline = require('readline');

/*
 * create a new readline.Interface instance that reads data from standard input
 * and write data to standard output
 */
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.on('close', () => {
 console.log("Close event received");
});

rl.question("Enter some thing to close the readline interface instance.", () => {
 rl.close();
});

Output
Enter some thing to close the readline interface instance.Hello
Close event received


Previous                                                 Next                                                 Home

No comments:

Post a Comment