我正在使用 PouchDB 和 Express 从数据库中获取文档:
server.js:
var express = require('express')
var PouchDB = require('pouchdb')
var app = express()
var db = new PouchDB('vuedb')
// handle PouchDB stuff
app.get('/docs', function(req, res) {
function map (doc, emit) {
if (doc.type === 'project') {
emit(doc.createdAt)
}
}
db.query(map, {include_docs: true}).then(function (projects) {
// _.map(projects.rows, (project) => (project.doc))
console.log('PROJECTS', projects)
})
// res.send()
})
client.js:
submit () {
this.$http.get('http://localhost:8080/docs').then(response => {
// console.log(response) does log the response, so this submit() action is working
}).catch(err => console.log(err))
}
我想确认是否正在获取项目
。但是 console.log('PROJECTS', items)
不会在终端中记录任何内容。为什么是这样? Express 中是否有特殊的记录方式?
最佳答案
不,不是那样的。问题是,它之前可能达到错误状态。 try catch 该错误
db.query(map, {include_docs: true}).then(function (projects) {
// _.map(projects.rows, (project) => (project.doc))
console.log('PROJECTS', projects)
}).catch(function (e) {
console.log(e);
})
关于javascript - 为什么 console.log 在以下 Express 代码中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35378364/