'use strict';

function f(x) {
    // do something...    
}

var readline = require('readline');

//创建readline接口实例
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

// ======= 方法一 =========
rl.question("input something:",function(str){
    console.log(f(str));

    // 不加close,则不会结束
    rl.close();
});
// =======================
// 或者这样:
// ======= 方法二 =========
// console.log('input something:');
// rl.on('line', function(line){
//     console.log(f(line));

//     // 不加close,则不会结束
//     rl.close();
// });
// ======================

rl.on('close', function() {
    process.exit(0);
});

相关文章:

  • 2021-11-13
  • 2021-08-03
  • 2021-12-13
  • 2021-12-03
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
  • 2022-02-27
猜你喜欢
  • 2022-01-21
  • 2022-12-23
  • 2021-08-05
  • 2021-04-10
  • 2021-08-18
  • 2022-12-23
  • 2022-02-07
相关资源
相似解决方案