Difference between Asynchronous and Synchronous methods
Synchronous methods | Asynchronous methods |
Synchronous functions are called blocking functions | Asynchronous functions are called non-blocking functions. |
It blocks the execution of the program until the file operation has finished processing. | It does not block the execution of the program. |
These functions take File Descriptor as the last argument. | These functions take a callback function as the last argument. |
Examples: fs.readFileSync(), fs.appendFileSync(), fs.writeFileSync() etc. | Examples: fs.readFile(), fs.appendFile(), fs.writeFile(), fs.stat() etc. |
Difference between Synchronous and Asynchronous Method of fs Module
Asynchronous fs methods in Node.js do not block the event loop and handle multiple operations concurrently, improving performance while Synchronous fs methods block the event loop until the operation completes, which can lead to inefficiencies and slower performance for I/O-bound tasks.
Table of Content
- FS Module in Node
- Synchronous Methods
- Asynchronous Methods
- Difference between Asynchronous and Synchronous methods
- When to Use Each