So in nodejs the methods are primarily nonblocking and by that I mean that the code inside of them is executed without stopping the execution for the other parts of the program until it finishes it's current operation.
A famous example would be reading a file using the fs module:
const fs = require('fs');
const data = fs.readFileSync('/file.md');
Here the second line will block the execution until it finishes the current task at hand, so this is Synchronous.
The counterpart would be the Asynchronous:
const fs = require('fs');
fs.readFile('/file.md', (err, data) => {
if (err) throw err;
});
A famous example would be reading a file using the fs module:
const fs = require('fs');
const data = fs.readFileSync('/file.md');
Here the second line will block the execution until it finishes the current task at hand, so this is Synchronous.
The counterpart would be the Asynchronous:
const fs = require('fs');
fs.readFile('/file.md', (err, data) => {
if (err) throw err;
});
Comments
Post a Comment