fs.writeFile doesn't return a promise when not promisified explicitly
See original GitHub issuewhen 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?
Issue Analytics
- State:
- Created 9 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
fs.writeFile in a promise, asynchronous-synchronous stuff
After 6 years, 10 answers and hundreds of votes, still no one has noticed that the for-loop ALWAYS exits in the first iteration...
Read more >From callbacks to fs/promises to handle the file system in ...
Let's promisify manually and wrap in a function the above code: const fs ... data) => { return new Promise((resolve, reject) => {...
Read more >An intriguing reason why Node.js libraries aren't promises by ...
So this one's for you, Ravish! Let's deal with the first question first: “Why doesn't the AWS node sdk just return a promise...
Read more >File system | Node.js v19.3.0 Documentation
The fs/promises API provides asynchronous file system methods that return promises. The promise APIs use the underlying Node.js threadpool to perform file ...
Read more >Using promises - JavaScript - MDN Web Docs
A Promise is an object representing the eventual completion or failure of an asynchronous operation. Since most people are consumers of ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dzuluaga try
after promisifying all. That should work according to the docs.
Thanks @capaj. I was just posting the same finding. Thanks again!