The fs module includes promisified methods since Node 11

Published at
Updated at
Reading time
1 min

This post is part of my Today I learned series in which I share all my learnings regarding web development.

That's a really quick one. ๐Ÿ™ˆ

When writing Node.js scripts and using the fs module I usually used the util.promisify method to ... well promisify the methods that I needed.

Today I learned that fs since Node.js 11 provides the methods in a promises property. ๐ŸŽ‰

const { readFile } = require("fs").promises;

// no util.promisify!!!
readFile(__filename, { encoding: "utf8" })
  .then(data => console.log(data));

Related Topics

See null comment.