Javascript 如何处理Express4获取响应

Javascript 如何处理Express4获取响应,javascript,node.js,express,Javascript,Node.js,Express,我可能做错了什么:我想使用NodeJS和Express4设置一个最小的API。我在router.js中有一条基本路线: const express = require('express'); const router = express.Router({strict: true}); router.get('/beats', (request, response) => { response.status(200).json({'thisIs': 'a test'}); }); 在

我可能做错了什么:我想使用NodeJS和Express4设置一个最小的API。我在router.js中有一条基本路线:

const express = require('express');
const router = express.Router({strict: true});

router.get('/beats', (request, response) => {
  response.status(200).json({'thisIs': 'a test'});
});
在我的前文件main.js中:

const beats = await fetch('/beats');
console.log(beats);
然而,以下是我在前端收到的回复:

如您所见,无法检索我在router.js中发送的JSON。。。 我哪里出错了?

获取方法的工作原理如下:

获取文本响应:

fetch('myUrl').then(result => result.text()).then(text => console.log(text));
fetch('myUrl').then(result => result.json()).then(json => console.log(json));
var myData = await fetch('myUrl').then(result => result.json()).then(json => json);
获取json响应:

fetch('myUrl').then(result => result.text()).then(text => console.log(text));
fetch('myUrl').then(result => result.json()).then(json => console.log(json));
var myData = await fetch('myUrl').then(result => result.json()).then(json => json);
不兑现承诺:

fetch('myUrl').then(result => result.text()).then(text => console.log(text));
fetch('myUrl').then(result => result.json()).then(json => console.log(json));
var myData = await fetch('myUrl').then(result => result.json()).then(json => json);

好吧,我明白了,结果我还是得到了一个承诺,似乎从来没有resolved@FuméeNoire只是在fetchTry
console.log(await beats.json())之前放置了一个wait