[英]Is it possible to console.log a GET request in in Express?
I am trying to test the results of my crud operations for a node.js/express app on the console but it doesn't seem to work for GET
only for POST. 我正在尝试在控制台上测试node.js / express应用程序的操作结果,但似乎不适用于仅用于POST的GET
。
I have this function: 我有这个功能:
app.get('/', (req, res) => {
db.collection('cars').find().toArray(function(err, results) {
console.log(results)
})
})
But I am unable to find a way to execute and retrieve the results in the console. 但是我找不到在控制台中执行和检索结果的方法。 How can I do this? 我怎样才能做到这一点?
try doing this: 尝试这样做:
db.open(function(err,db){ // <------everything wrapped inside this function
db.collection('cars', function(err, collection) {
collection.find().toArray(function(err, results) {
console.log(results);
});
});
});
that looks like MongoDB to me, and if it is, then I don't think the cursor.toArray() method takes a callback function at all. 在我看来,它看起来像MongoDB,如果是的话,那么我不认为cursor.toArray()方法完全采用了回调函数。 Instead it iterates over all results and exhausts the cursor for you. 相反,它会遍历所有结果并为您耗尽光标。
try console.log(db.collection('cars').find().toArray());
尝试console.log(db.collection('cars').find().toArray());
. 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.