8
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Node.jsでコマンドライン上の対話型アプリケーション

Posted at

Node.js v8.11で動作確認しました。

const readline = require('readline');

const reader = readline.createInterface({
  input: process.stdin,  // 標準入力
  output: process.stdout // 標準出力
});

// Enterキー押下で読み込み
reader.on('line', line => {
  console.log(line);
  reader.prompt();
});

// ctrl+Cで終了
reader.on('close', () => {
  console.log("finish");
});

// コマンドプロンプトを表示
reader.prompt();
8
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?