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 ?