How does nodejs handle monitoring?

  node.js, question

As the following common code:

var http =require('http');
 http.createServer(function(req,res){
 //XXXX
 mycode here
 }).listen(3000);

If many requests arrive at the same time, how will nodejs’s single thread handle them? Do you wait until the previous request is processed before accepting the next request? It seems that it should not be. If it is, if the logic of processing is complicated, it will be slow. But if you pause in the middle and run to the front to execute, isn’t it possible to generate data conflicts? This is similar to java’s thread safety. For example, the following:

var http =require('http');
 var myVar=1;
 http.createServer(function(req,res){
 MyVar=myVar plus 1;
 //XXXX
 mycode here;
 var k=myVar;
 if(k==myVar){
 XXXX;
 console.log('ok');
 bracket
 }).listen(3000);
Obviously, if you use just logic, it is possible not to output OK.

Nodejs’ handling of requests is of course serialized. So it has no thread synchronization problem. This principle shows that NODEJS is not suitable for processing heavy Central Processor resources.
This design has both advantages and disadvantages. The advantages are, of course, greatly improved processing power (because thread switching also takes a lot of time) and greatly reduced programming difficulty (we no longer need to consider the problems of thread deadlock and synchronization).
The disadvantage is that the processing time of each request cannot be too long, otherwise it may affect the processing of other requests. For example, if there is the following code in the request processing, it may block:

for(var i=0;  i<100000;  I plus)
 console.log(rf.readFileSync("test","utf-8"));
 bracket

Most time-consuming IO operations require callback function processing. But FeiCentral Processor’s operation is simply not feasible.