0

I know that in nodejs , it has function fs.readFileSync, when you calling it , you just need to write code like :

function f1(){
    const text = fs.readFileSync('filepath',{encoding:'utf8'});
    console.log(text);
}

The function f1 is not async function, and there is no await before fs.readFileSync() , but the file is really read by sync , and console.log(text) can print the full content , so , how can I write a function like readFileSync , when calling it , does not need to use async and await ?

I know that nodejs addon can , but what if just purely javascript code ?

  • Does this answer your question? [If nodejs uses non blocking IO, how is fs.readFileSync implemented?](https://stackoverflow.com/questions/17336779/if-nodejs-uses-non-blocking-io-how-is-fs-readfilesync-implemented) – Sergey Sosunov Feb 11 '23 at 03:12

0 Answers0