I'm trying to solve this issue but I am stuck! the function should return some data after reading the file but I can not figure out how to do it. The function returns undefined
instead of the corresponding data.
const fs = require('fs');
const path = require('path');
const { resolve } = require('path');
const findFile = (fileName) => {
const filePath = path.join(__dirname, fileName);
return fs.promises.readFile(filePath, { encoding: 'utf-8' });
};
const processDataFromFile = (inputFile) => {
findFile(inputFile)
.then((data) => {
const dataProcessed = doSomeStuffWith(data); // do some stuff with data
return dataProcessed;
})
.catch((err) => console.log(err));
};
console.log(processDataFromFile('fileToRead.txt')); // it should return the data instead of undefined
What am I doing wrong? What Javascript feature am I not aware of?