0

I'm trying to read some input from the repl.it terminal, but the program terminates before the readline interface closes.

I'm currently using code provided directly by node.js. Link to the documentation I'm getting it from is here

Here's all of my code:

const readline = require('readline');

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

rl.question('What do you think of Node.js? ', (answer) => {
  // TODO: Log the answer in a database
  console.log(`Thank you for your valuable feedback: ${answer}`);
  rl.close();

});

Expected result: The question shows up and the program waits for an answer. Then, it logs Thank you for your valuable feedback: <answer-here> and terminates

Result:
enter image description here

Seblor
  • 6,947
  • 1
  • 25
  • 46
bluelhf
  • 71
  • 1
  • 7
  • I'm not sure about repl.it, but if you copy the code into a js-file (ie `index.js`) and run it with `node index.js`, it does exactly what you're expecting. – Patrick Jul 15 '19 at 13:30
  • Could you share the repl.it link ? – Seblor Jul 15 '19 at 13:30
  • Possible duplicate of [NodeJS "readline" module not outputting prompt](https://stackoverflow.com/questions/51251494/nodejs-readline-module-not-outputting-prompt) – Seblor Jul 15 '19 at 16:03

2 Answers2

1

Unfortunately this unexpected behavior due to an older system we have running for Node.js where we have two "modes" for execution, eval mode (one .js file, REPL can interact with program, and literally evals the code so you won't have async capabilities and such) and project mode (multiple .js files, REPL cannot interact with program).

For now, you can fix it by adding an empty .js file to kick it into project mode.

Example repl: https://repl.it/@timmy_i_chen/CandidGargantuanArchive

EDIT: A fix will apparently take longer than I realized. This is something we're cognizant of and will be trying to fix in the future.

tic
  • 137
  • 12
-2

Use the sdin icon to put yer text in, maybee?