You are using a recent version of Node.js and are tired of working with callbacks with Node native modules.
Chances are, there is a version of that module that is using promises out of the box.
$ touch index.js
const fs = require("fs").promises;
fs.readdir(process.cwd()).then(files => {
console.log(files);
}).catch(error => {
console.error(error.message);
});
$ node index.js
Or
$ touch index.mjs
import {promises as fs} from "fs";
fs.readdir(process.cwd()).then(files => {
console.log(files);
}).catch(error => {
console.error(error.message);
});
$ node index.mjs
Top comments (0)