Will Node.js get blocked when processing large file uploads?

前端 未结 3 769
温柔的废话
温柔的废话 2020-12-28 18:18

Will Node.js get blocked when processing large file uploads?

Since Node.js only has one thread, is that true that when doing large file uploads all other requests wi

3条回答
  •  攒了一身酷
    2020-12-28 19:14

    That depends on the functions used for accomplishing that task. If you are using asynchronous functions, then Node.js will not block. But there are also synchronous functions, for example fs.readFileSync (FileSystem Doc), that will block execution.

    Just take care and choose asynchronous functions. This way Node.js will keep running while slow tasks/waits are completed by external libraries. Once those tasks are completed, the Event Loop will take care of the result and execute your callbacks.

    You can read more about the Event Loop here: Understanding the Node.js event loop

提交回复
热议问题