Readline-sync blocks subsequent http requests?

  node.js, question

I want to request the server-side interface through the command-line question-and-answer method in the loop, using thereadline-syncHowever, it was found that no http request would be issued unless the loop ended.

The code is as follows

Server side

 var http = require("http");
 var i=0;
 http.createServer(function(request, response) {
 Log ('requestreceived' plus i);
 response.writeHead(200, {"Content-Type": "text/html;  charset=utf-8"});
 console.log('server started');


// readline.js
 // npm install readline-sync
 // npm install request
 var readline = require("readline-sync");
 var request = require("request");
 for (var i = 0;   i < 10;  I plus)
 var ans = readline.question("do requ ?"  );
 if (ans == "y") {
 console.log("begin to request");
 request("http://localhost:9990", function (err, resp, body) {
 Log ("get->" plus body);

The implementation is as follows:

On the left is the server side and on the right is the readline client.

For the first four cycles, the server did not respond.

After 10 times of execution, the server will output it instantly.

There are two questions:

  1. Why can’t the server accept the request until the loop ends?

  2. How can I modify it so as to initiate the request immediately after answering Y? (The request itself is asynchronous).

Thank you very much.

Try adding ans.close () after each answer