如何在node.js中正确调试简单的Prom?

问题描述 投票:1回答:1

我的问题是,当我调试节点应用程序时,仅通过运行debug就看不到承诺的结果。

例如,我有以下无法调试的代码:

sampleRepository
    .find()
        .then(result => result)  // breakpoint goes here
        .catch(err => err)

当我在其中放置断点时,看不到结果变量的值。因此,我必须重构代码以解决该问题。我正在做的工作是:

sampleRepository
        .find()
            .then(result => {
                return result; // breakpoint goes here
            })  
            .catch(err => err)

有效,因为现在我可以看到“结果”变量的值,但是我必须每次都重构代码。有没有更简单的方法来调试这些Promise而不是重构代码?

node.js debugging promise visual-studio-debugging
1个回答
0
投票

实际上vscode已经支持此功能。可以在then处理程序上设置断点,然后在击中断点后使用step into。检查我制作的这个小.gif文件:https://ibb.co/YLNmzZ3

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.