0

When I run this code the log file name will be 'undefined'. the checkfile return the correct file name, but the filename variable won't be equal with that.

const logger = async () => {
  filename = await checkFile();
  openFile();
}

const checkFile = async () => {
  originfn = "xyservice_" + await datetime.date() + ".log";

  fs.access(`logs/${originfn}`, fs.constants.F_OK, (err) => {
    //console.log(`logs/${origfn} ${err ? 'does not exist' : 'exists'}`);
    if (err) {

      return originfn;
    } else {

      return originfn + ".2";
    }
  });
}

const openFile = async () => {
  fs.appendFile(`logs/${filename}`, await time() + `Logging system 
started...in file logs/${filename}`, function(err) {
    if (err) console.log(err);

    console.log('Log file created...');
  });

  return;
}

Then how is this code working? I do not understand. Whats the diffs?

const permParser = async (perms) => {

let permissions = {}

//general code

return permissions;
}

I call like this
await permParser(permtopars)

mszabolcs
  • 67
  • 1
  • 10

0 Answers0