0
function adminCheck(inp) {
    fs.readFile('./files/admins', 'utf8', (err, data) => {
        if (err) {
            console.log(err);
        }
        if(data.includes(inp)){
            console.log('Admin')
            return true;
        }else{
            console.log('Non-admin')
            return false;
        }
    })
};

I want to check if a user is in the admin file. The console messages in the function are signaling correctly when I add/remove a username. But the function is not returning T/F when I call with:

console.log(adminCheck(request.session.username))

It just console logs "undefined" so I can't do anything with it, I cannot figure out why. Any thoughts?

CLipp
  • 100
  • 5
  • 2
    `adminCheck` doesn't have a `return` statement. (Only the arrow function you pass as a callback to `readFile` does). – Quentin May 05 '22 at 16:41
  • then it runs into scope issues – CLipp May 05 '22 at 16:45
  • @CLipp: What "scope issues"? At a glance it looks like the goal here is for `adminCheck` to return a Promise, making use of [the Promise-based `fs` operations](https://nodejs.org/api/fs.html#fspromisesreadfilepath-options). – David May 05 '22 at 17:00

0 Answers0