首页 > 解决方案 > 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.

标签: node.jspromise

解决方案


推荐阅读