function done()
{
console.log("Resized file at : " + resizedfile)
resolve(resizedfile)
}
function resize(filename)
{
return new Promise(function(resolve,reject){
if(!filename.endsWith(".png"))
{
reject(new Error(“File does’t ends with .png”))
}
else
{
let resizedfile = filename.split(".")[0] + “-resized.png”
console.log("Starts resizing : " + resizedfile)
setTimeout(done,3000)
}
})
}
//How to pass arguments to the done function defined outside the setTimeout
//Another Doubt related to node js
file: lib.js
function awesomefunction()
{
console.log(“OMG! This is awesome”)
}
console.log("Hey , Whts gng on ? ")
module.exports.obj = {
a:10,
b:20,
c:30
}
File- script.js
var msg = require(’./lib.js’)
console.log(msg)
console.log(msg.message)
console.log(msg.obj.a)
console.log(msg.obj.b)
console.log(msg.obj.c)
//On running script.js file why does it print the content written in console.log() of the file lib.js
while we are only downloading the module.export or exports object into script.js from lib.js
??
//Q3.
Why can’t we assign the variables to the asynchronous functions ??
e.g a = fs.readFile(__dirname + ‘/myfile.txt’, function(err,data){ if(err) throw err; console.log(data) })