node.js - How can you store the output of a promise into a variable?
问题描述
The following code outputs the result of the promise. However, all my attempts to capture the output of the context.log into a variable have failed.
// Get light configuration
client.listLights('all').then(result => {
context.log(JSON.stringify(result, null, "\t"));
myvariable = result;
})
.catch(err => {
context.log.error('Failure ' + err);
});
context.log(myvariable);
The output on myvariable is undefined.
解决方案
推荐阅读
- swift - 图片未上传,而 API 调用(通过 PATCH 方法)成功,Alamofire,Swift
- java - 在数据库中存储“用户收到通知的次数”
- batch-file - 如何使用凭据将 SQL Server 备份文件从一个网络复制到另一个网络?
- ios - 在 swift 4 / Xcode 10 中第二次启动 App 时跳过初始视图控制器
- javascript - NodeJS JavaScript 和 Mongo 通信
- git - 从 Bitbucket 克隆到本地 AndroidStudio 项目
- r - 如何根据数字和字符条件将数据从一个数据库添加到另一个数据库
- java - GPS 跟踪在 Android Marshmallow 上工作,但在较低的 API 上总是返回 0
- javascript - 如何在javascript中用*替换@之前的电子邮件ID文本?
- css - CSS Grid - 具有循环逻辑的行跨越