mercredi 23 décembre 2020

typescript function skips if statments

export function GetData(uuid: any): string {
  var dirPath: string = path.join(__dirname, "../Container/" + uuid);
  console.log(dirPath);
  if (fs.existsSync(dirPath) == true) {
    fs.readFile(dirPath, "utf8", (err: any, string: any) => {
      if (err) {
        console.log("ERROR: " + err);
        return "null1";
      } else {
        console.log("token: " + JSON.parse(string).token);
        return JSON.parse(string).token || "";
      }
    });
  } else {
    console.log("will send null");
    return "null2";
  }
  return "end";
}

I have no idea why it's happening and in the console I also gives out "token: " and the token part of the json but if i run it in as a function and console log the result it gives me "end"

Aucun commentaire:

Enregistrer un commentaire