when I have code:
var Promise = require('bluebird');
var fs = Promise.promisifyAll(require('fs'));
fs.writeFile('./justATest.txt', 'hello', {}).then(function() {
console.log("succesfulle written");
});
I get a
fs.writeFile('./justATest.txt', 'hello', {}).then(function() {
^
TypeError: Cannot call method 'then' of undefined
It works when I promisify it explicitly:
var Promise = require('bluebird');
var writeFile = Promise.promisify(require('fs').writeFile);
writeFile('./justATest.txt', 'hello', {}).then(function() {
console.log("succesfulle written");
});
So shouldn't it work even in the first case?
It doesn't overwrite the methods, since that would break any code using the module. The promise-returning versions have Async suffix by default. More at documentation
@petkaantonov I thought it created a whole new 'proxy' object under the hood. Allright thanks.
I know this has been locked. But I only was able to make it work as per @capaj workaround. I didn't get your comment @petkaantonov. Could you please post the code to support promisifyAll?
@dzuluaga try
fs.writeFileAsync('./justATest.txt', 'hello', {}).then(function() {
console.log("succesfully written");
});
after promisifying all. That should work according to the docs.
Thanks @capaj. I was just posting the same finding. Thanks again!
Most helpful comment
@dzuluaga try
after promisifying all. That should work according to the docs.