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

My Node.js process doesn't terminate when using prompt function #9

Open
davideicardi opened this issue Mar 30, 2016 · 2 comments
Open

Comments

@davideicardi
Copy link

I suspect that the problem is that process.stdin is still referenced. See this SO answer.

I have tried another approach using readline:

const readline = require('readline');

function prompt(msg){
  return new Promise((resolve, reject) => {
    const rl = readline.createInterface({
      input: process.stdin,
      output: process.stdout
    });

    rl.question(msg, (answer) => {
      rl.close();
      resolve(answer);
    });
  });
}

What do you think?

@eladnava
Copy link

eladnava commented May 2, 2016

You need to explicitly pause stdin after using co-prompt with the following code, at the end of your execution flow:

// Gotta pause stdin after we're done so it doesn't look like the process is stuck
process.stdin.pause();

@afoeder
Copy link

afoeder commented Jan 10, 2020

should this be added to the documentation? The need to add a process.stdin.pause();?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants