【问题标题】:Is it possible to view this json data whilst sending it to the server with console.log?是否可以在使用 console.log 将其发送到服务器时查看此 json 数据?
【发布时间】:2019-11-30 18:42:28
【问题描述】:

我想查看发送到服务器的 JSON 数据以及发送它。但是,我无法理解 promise 对这个函数的作用。

如果我 console.log() 函数的主体,我会得到 Promise { pending }。我不能在承诺之外console.log(users),因为“用户”超出了范围。

因此,有没有办法让我查看提供的代码正文中的数据?

function getAll(req, res, next) {
    userService.getAll().then(users => res.json(users)).catch(err => 
next(err)); 
}

预期的结果是控制台中的一些 JSON 数据。

【问题讨论】:

    标签: javascript json function express promise


    【解决方案1】:

    你可以这样做:

    function getAll(req, res, next) {
        userService.getAll().then(users => {
            console.log(users)
            res.json(users)
        }).catch(err => 
    next(err)); 
    }
    

    【讨论】:

      猜你喜欢
      • 2015-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多