wyc
wyc

Reputation: 55283

Why isn't console.log working in the following Express code?

I'm using PouchDB and Express to fetch documents from a database:

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))
}

I want to confirm whether the projects are being fetched. But console.log('PROJECTS', projects) doesn't log anything in the terminal. Why is this? Is there a especial way of logging stuff in Express?

Upvotes: 0

Views: 104

Answers (1)

user1695032
user1695032

Reputation: 1142

No, it's not that. The thing is, it probably reaches an error state before. Try to catch that error

  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);
  })

Upvotes: 1

Related Questions