Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readline not working as expected in NodeJS #1072

Open
mzoliker opened this issue May 4, 2024 · 1 comment
Open

Readline not working as expected in NodeJS #1072

mzoliker opened this issue May 4, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mzoliker
Copy link

mzoliker commented May 4, 2024

Hi! First, many thanks for supporting process.stdin in nodejs! This was really a feature I was waiting for! :-)

Please note that the sample code below does not work as expected though, as the program hangs (waiting for further input) and does not exit after input as it should. rl.close() should indeed close the interface and let the program close.

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
rl.question('Username: ', user => {
  console.log(`Hello ${user}`);
  rl.close();
});

Kind regards,
Maurice

@bummoblizard bummoblizard added the bug Something isn't working label May 4, 2024
@bummoblizard
Copy link
Member

bummoblizard commented May 4, 2024

Thanks for testing the feature! I can confirm this issue and will look into it. As a workaround, it is possible to end the program by pressing command-c on the keyboard (or its button).

Update: Not quite sure what caused this but another workaround I found is setTimeout(() => {rl.close()}).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

2 participants