This work fine, result undefined as expected
const fs = require('fs');
const path = require('path');
const { promisify } = require('util');
fs.truncate = promisify(fs.truncate);
fs.truncate(path.resolve(__dirname, '../.logs/123.log'))
.then(console.log)
.catch(console.error);
fs.open = promisify(fs.open);
But if I put fs.open = promisify(fs.open) above invoking fs.truncate, my promise do not resolve or reject
fs.truncate = promisify(fs.truncate);
fs.open = promisify(fs.open);
fs.truncate(path.resolve(__dirname, '../.logs/123.log'))
.then(console.log)
.catch(console.error);
If I get this right, you do not need to rewrite fs methods, it can break fs module. Try this:
const truncate = promisify(fs.truncate);
const open = promisify(fs.open);
@vsemozhetbyt I think you're right. 袛褟泻褍褞 ;)
Starting in node.js 10.0.0, there are experimental fs.promises functions that are not promisify wrappers... try fs.promises.truncate for instance...
Most helpful comment
Starting in node.js 10.0.0, there are experimental
fs.promisesfunctions that are not promisify wrappers... tryfs.promises.truncatefor instance...