The fs module includes promisified methods since Node 11

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 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" ) ; const { promisify } = require ( 'util' ) ; const promisifiedReadFile = promisify ( readFile ) ; promisifiedReadFile ( __filename , { encoding : "utf8" } ) . then ( data => console . log ( data ) ) ; const { readFile } = require ( "fs" ) . promises ; readFile ( __filename , { encoding : "utf8" } ) . then ( data => console . log ( data ) ) ;