Friday, 18 January 2019

NodeJS: Where does my code go?

Hello,I'm new to NodeJS (and event driven programming in general). I'm working through some tutorials and have a question about the flow of execution. Suppose I have a really simple program like this:function ask(){process.stdout.write("What is your name? > ");}process.stdin.on("data", (data) => {process.stdout.write(\\${data}\n\);});ask();And I run this program using:node ask.jsWhen I first run the program, it asks me the question, I type an answer, and it prints it to the screen. That all makes sense.But then the process just hangs. If I type in more data, the event handler executes again, but then it continues waiting for input. Can someone explain what is happening? I don't understand why the process doesn't terminate. It's like adding the event handler prevents it from terminating, and I don't understand why.

Submitted January 18, 2019 at 04:06PM by jecanne

No comments:

Post a Comment