I am trying to understand the following problem:
var fs = require('fs');
var Promise = require('bluebird');
Promise.promisifyAll(fs);
fs.readFileAsync('read.js','utf8').then(function(content) {
console.log(content);
}).catch(function(error) {
console.log(error);
});
I understood that since I am promisifying fs library I can use readFileAsync
as promise. But if i change the name of readFileAsync
to readFileAs
I am getting the following error:
C:\Users\nniranja\Venkat\promises_github.js:17
fs.readFileA("read.js",'utf8').then(function(content)
^
TypeError: undefined is not a function
at Object.<anonymous> (C:\Users\nniranja\Venkat\promises_github.js:17:4)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
Please help me to understand the significance of Async. Thank you.
readFileAs
is not a function in the fs module, nor is it a property that bluebird would add to the module. So, it is expected that there is noreadFileAs
function found.