Using callbacks with async await or promises
In the modern javascript universe, most of the libraries now support async/await or promise syntax. But there are some libraries that do not support this syntax or you might need to work some of your old which are written using callbacks and you don't want to touch it, but just want to use it. Let's take the example of the following code snippet // filename read-my-file.js const fs = require ( "fs" ); // Use fs.readFile() method to read the file function readMyFile ( filePath , callback ) { fs . readFile ( filePath , "utf8" , function ( err , data ) { if ( err ) { //log error silently or throw error callback ( err ); } callback ( null , data ); }); } module . exports = { readMyFile }; let's say now you want to use this readMyFile, what you will need to do is // filename: main.js const fileReader = require ( "./read-my-file" ); function printMyData () { fil...