Javascript 获取RESTAPI节点数据导出

Javascript 获取RESTAPI节点数据导出,javascript,node.js,api,rest,Javascript,Node.js,Api,Rest,我想通过检索用户的信息来返回用户是否存在,如果存在信息,则返回true,否则返回false。问题是,在我的res.on'end'中,我很好地恢复了用户数据,但不可能在这个函数之外恢复他的数据。你有什么想法吗 this.api.getEnv=http-dev或https-prod GetUserById=函数id{ const req=this.api.getEnv.requestthis.api.ApiHeader'/user/'+this.PlayerIdentifiersid,许可证'GET

我想通过检索用户的信息来返回用户是否存在,如果存在信息,则返回true,否则返回false。问题是,在我的res.on'end'中,我很好地恢复了用户数据,但不可能在这个函数之外恢复他的数据。你有什么想法吗

this.api.getEnv=http-dev或https-prod

GetUserById=函数id{ const req=this.api.getEnv.requestthis.api.ApiHeader'/user/'+this.PlayerIdentifiersid,许可证'GET',res=>{ 让body=; 关于'data',d=>{ body+=d; }; res.on'end',函数{ const user=JSON.parsebody; console.loguser; }; 如果用户{ 返回true; }否则{ 返回false; } };
常量user是在res.on'end'函数内创建的,因此在该函数外不可见。为了使其工作,可能需要将res.send放在res.on'end'函数内?类似于res.senduser?true:false;就在console.loguser;您好,谢谢您的回答。我遇到了一个新错误:res.send不是函数。@Evert,非常感谢,这正是我需要的。
res.on('end', function () {
  const user = JSON.parse(body);
  console.log(user);
  if (user) {
    return true;
  } else {
    return false;
  }
});