What is thunkify?
The 'thunkify' npm package is used to convert functions that take a callback into functions that return thunks. Thunks are functions that encapsulate a computation or action to be performed later, which can be particularly useful in asynchronous programming.
Convert callback-based functions to thunks
This feature allows you to convert a function that uses a callback (like 'fs.readFile') into a function that returns a thunk. The thunk can then be called with a callback to execute the original function.
const thunkify = require('thunkify');
const fs = require('fs');
const readFileThunk = thunkify(fs.readFile);
const thunk = readFileThunk('example.txt', 'utf8');
thunk((err, data) => {
if (err) throw err;
console.log(data);
});