Async

Q: what are common async function?
ans:-  fs.readFile - to read a file from your filesystem
Fetch - to fetch some data from an API endpoint.

=>fs means FILE SYSTEM MODULE


1)  Exmaple of async fs.readFile.
ans:-
step1  :  make a normal file like test.txt
step 2 :  make second file which is js flie
step 3 :  code in js file
    const fs = require("fs");
fs.readFile("test.txt","utf-8", function(err,data) {
console.log(data);
})
console.log("Hi There");



2) Exmaple of async fs.readFile.
ans:-
step1  :  make a normal file like test.txt
step 2 :  make second file which is js flie
step 3 :  code in js file
    const fs = require("fs");
fs.readFile("test.txt","utf-8", function(err,data) {
console.log(data);
})
console.log("Hi There");

let a=0;
for(let i =0; i<10000; i++) {
a++;
}
console.log("Hi There 2");


3)   Exmaple of async.
ans :  
console.log("hi there");
setTimeout(function(){
console.log("from inside async fn")
},20000);

setTimeout(function(){
console.log("from inside async fn")
},10000);

let a = 0; for (let i =0; i<10 ; i++){
a = a+ 1;
}
console.log(a);



Comments

Popular posts from this blog

VERTICAL SCALING 💋

CyberSecurity

c program