How to export the value of the callback function in async

  // token
  async getLocalAccessToken() {
    const token = await fs.readFile("wechatToken. txt", "utf8", (err, data) => {
      return token;
    });
    return token;
  }
  // accesstoken
  async updateMenu() {
    // const access_token = await this.ctx.service.home.getLocalAccessToken();
  }

I want to call getLocalAccessToken in the updateMenu function to get the value of token. I know it is wrong to write this way. If I call it asynchronously, I will execute return token; first. How do I write it?

May.23,2022

 getLocalAccessToken() {
    return new  Promise((resolve,reject)=>{
        fs.readFile('wechatToken.txt','utf8',(e,data)=>e?reject(e):resolve(data));
    });
  }

caller

const access_token = await this.ctx.service.home.getLocalAccessToken();

needs to return a Promise

Menu