Friday 14 April 2017

intergrate function readline from node.js module into read_line function to get user input

//normal nodejs module readline
const readline = require('readline');
//I want to integrate readline module into my function read_line so as to I can get user input by use read_line ,but my mind  is wrong.
//I know the reason is that js function will not be blocked by Function,but I am not familiar with nodejs,how can it block subsequent code run?
function read_line() {
    var input;
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    rl.on('line', function (input) {
        this.input = input;
        rl.close();
    });
    return input;
}

//it will run right now,return undefined
var s = read_line();
//i want to console the user input
console.log(s);

I want to integrate readline module into my function read_line so as to I can get user input by use read_line ,I need help!



via Chen.caijun

No comments:

Post a Comment