Javascript 在使用console.log将json数据发送到服务器时,是否可以查看该json数据?

Javascript 在使用console.log将json数据发送到服务器时,是否可以查看该json数据?,javascript,json,function,express,promise,Javascript,Json,Function,Express,Promise,我想查看发送到服务器的JSON数据,并发送它。然而,我很难理解承诺对这个函数有什么作用 如果我console.log()我得到的函数体Promise{pending}。我不能console.log(users)超出承诺范围,因为“users”超出范围 因此,我是否有办法查看所提供代码主体内的数据 function getAll(req, res, next) { userService.getAll().then(users => res.json(users)).catch(er

我想查看发送到服务器的JSON数据,并发送它。然而,我很难理解承诺对这个函数有什么作用

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

因此,我是否有办法查看所提供代码主体内的数据

function getAll(req, res, next) {
    userService.getAll().then(users => res.json(users)).catch(err => 
next(err)); 
}
预期结果是控制台中的一些JSON数据。

您可以这样做:

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