Esa Toivola
Esa Toivola

Reputation: 1538

Letting the user edit a single text line in Node.js

In my Node.js application I want to display text lines to user and the user should be able to accept the line or edit it. I have looked for a npm module implementing a simple text editor in text terminal but with no luck. Does anyone know such a module? Or should I save the text line to a file and then spawn an external text editor for editing? It sounds like overkill for my situation. My app would be run in Windows.

Upvotes: 0

Views: 690

Answers (1)

robertklep
robertklep

Reputation: 203484

You could use the built-in readline module:

var readline = require('readline');

var rl = readline.createInterface({
  input : process.stdin,
  output: process.stdout
});

rl.write(YOUR_LINE_HERE);
rl.question('> ', function(answer) {
  console.log('User entered: ', answer);
});

Upvotes: 1

Related Questions