What is the difference between single-threaded and non-blocking I / O in NodeJs?

I read and looked through as much NodeJs code as possible, but I'm a bit confused about this:

What does Node mean as a single-threaded value, and what does non-blocking I / O mean? I can achieve the first by creating a child process, and the second by using an asynchronous library. But I would like to understand what this means and how non-blocking I / O still slows down your application.

+3
source share
1 answer

I will try my best to explain.

, Node.js Javascript - - . , - ( ) , . , - . , , , Node.js, "", .

, , , . , , . - "-" (, ) , .

, , -.

:

console.log(readFileSync(filePath))

, :

readFile(filePath)

readFile (, nano-), . readFile , , , readFile . , :

readFile(filePath, function(err, contents) { console.log(contents))

, readFile . . ( readFile). , .

, - (, 10 , 100 1000 ), , . .

Async. .

  • - Node.js , ​​. , Node.js . , , . , Node.js. .

  • Async -, Node.js . Node.js , , . Async .

Node.js , !

:

+8

Source: https://habr.com/ru/post/1610347/


All Articles