Tuesday, 2 October 2018

node.js: readline: rl.setPrompt(prompt)

rl.setPrompt(prompt)
This method sets the prompt that will be written to output whenever rl.prompt() is called.

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('line', (data) => {
 console.log(`Hello ${data}, How are you`);
 rl.close();
});

rl.setPrompt("Please Enter your name : ");
rl.prompt();


Output

Please Enter your name : Krishna
Hello Krishna, How are you




Previous                                                 Next                                                 Home

No comments:

Post a Comment