Why wont this function return any data?

35 Views Asked by At

I want to read a file using a function but it always just returns undefined.

function ReadFromFile(FileName) { 
    data = fs.readFile(`./ServerSaves/${FileName}.txt`, 'utf8', (err, data) => {
        if (err) {
            console.error(err);
            return;
        } 
            
        return data;
        
    }); 
    console.log(data)
    return data;
}

I tried many things already but the output was always either "undefined", "[object Promise]" or an error.

0

There are 0 best solutions below