What could be causing the console.log to not work in this Express code snippet?

I'm currently utilizing PouchDB in conjunction with Express for retrieving documents from a database:

server.js:

var express = require('express')
var PouchDB = require('pouchdb')

var app = express()
var db = new PouchDB('vuedb')

// handling PouchDB operations

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) successfully logs the response, indicating that the submit() action is functioning
  }).catch(err => console.log(err))
}

I am eager to verify whether the projects are indeed being fetched. Nonetheless, the statement

console.log('PROJECTS', projects)
fails to display any output in the terminal. What could be causing this issue? Are there specific methods for logging information in Express?

Answer №1

No, the issue may not be what you think. It might be encountering an error state earlier on. Make sure to handle 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);
  })

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A video streaming server using NodeJS Express, where the server has control over the range

Currently, I am exploring a question without any specific code. My query revolves around the byte range header in video streaming. Most resources I've come across, like articles and discussions on Stack Overflow, suggest that the client specifies the ...

HTML // jQuery - temporarily mute all audio for 10 seconds after page reload

Is there a way to automatically mute all audio sounds on my website for the first 10 seconds after it is reloaded, and then unmute again? <audio id="musWrited" autoplay> <source src="sound/soundl.mp3" type="audio/mp3" /> // < ...

What is the best way to combine two arrays of objects in AngularJS?

How can I merge the existing object array with another one in AngularJS to implement the "load more" feature? Specifically, I want to add the AJAX response to the existing data each time. Currently, I have a variable called $scope.actions that holds the ...

Toggle visibility of div content when hovering over a link by leveraging the data attribute, with the div initially visible

I have a collection of links: <p><a href="#" class="floorplan initial" data-id="king"><strong>King</strong></a><br> 4 Bedrooms x 2.5 Bathrooms</p> <p><a href="#" class="floorplan" data-id="wood">< ...

What is the best way to handle rejecting an invalid JSON body when working with Express or Body-Parser?

I'm currently developing an application that strictly accepts a JSON body type. I am utilizing body-parsers and express for this purpose. However, the recurring issue I encounter is that when an invalid JSON body is sent, my program throws back an und ...

My server keeps crashing due to an Express.js API call

I'm completely new to express.js and API calls, and I'm stuck trying to figure out why my server keeps crashing. It works fine the first time, rendering the page successfully, but then crashes with the error: TypeError: Cannot read property &apo ...

Once the image is requested in HTML, three.js makes a subsequent request for the same image

This is a block of code. let image = new THREE.TextureLoader().load("http://odf9m3avc.bkt.clouddn.com/1493817789932.jpg") <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/88/three.min.js"></script> <img class='preLoad&apo ...

Exploring cookie evaluation in AngularJS routes and templates

I am in the process of implementing a login system using cookies to ensure that a user stays logged in even after leaving the application. While I have successfully set the cookie, I am unsure of how to utilize it to restrict access to the login screen for ...

Comparing obj.hasOwnProperty(key) with directly accessing obj[key]

Consider the scenario where I need to determine if a property exists within an Object. A comparison between two methods caught my attention: if(object.hasOwnProperty(key)) { /* perform this action */ } OR if(object[key]) { /* perform this action */ ...

Is there a way to enlarge an iFrame to fill the entire screen with just a button click, without using JavaScript

I am currently attempting to achieve full screen mode for an iFrame upon clicking a button, similar to the functionality on this site. On that website, there is a bar that expands to full screen along with the embedded game, which is what I am aiming for. ...

Can someone help me identify the location in my Express app where the response is being sent or finished?

My application is throwing the error message Error: Can't set headers after they are sent. It seems like a response is being sent before the intended response, but I am unsure of the source. Is there a way to log to the console when a response has bee ...

Programmatically control the opening and closing of a React Material UI Snackbar component

Currently, I am facing some challenges while working on programming a Single Page Application (SPA) using React and Material-UI. In my project, I have created a modal login box that gets triggered by a button on the navigation bar. Upon clicking submit, I ...

Replace the current CSS styles of a pre-installed package

I recently added a package for a type writer effect, but I'm having trouble with it not overriding the CSS styles I've set in the component. Here's an example of what I have: <template> <v-row class="hero" align-content= ...

Error in Javascript: Character class range is not in order

My regular expression (regex) seems to be incorrect: var domain = "google\.com\.br"; var reEmail = new RegExp("^([A-Za-z0-9_\-\.])+\@" + domain + "$"); I am trying to use this regex to validate an email address. Here is an exampl ...

Why won't my code display in the div element as expected?

I am in the process of developing a gameserver query feature for my website. The objective is to load the content, save it, and then display it later. However, I am encountering an issue with the echoing functionality. The element is selected by its ID and ...

Transform the file format from .casa-model to .obj

Looking for a way to convert a file with the extension .casa-model to .obj format. Is there any solution available? Find the model here. ...

In React version 16 and d3 version 4, if you try to use the mouse functionality from d3-selection, you may encounter a TypeError stating that it cannot read the property 'sourceEvent' of

Exploring the integration of d3 with React by incorporating the mouse feature from d3-selection module import { selectAll, select, mouse } from 'd3-selection'; Encountering an issue while attempting to utilize : mouse(e.target) or mouse(select( ...

Changing or toggling the visibility of links once the week is finished

I have a total of 4 links available, but I want to display only one link at a time, highlighting a different lunch option every week. Once all 4 weeks have passed, the first lunch menu will be shown again, starting from Monday. <div class="wrapper& ...

How can I dynamically change a key in an object and replace it with a custom name while also updating its value?

Transform this =>>>>> {1: "Baroque", 2: "Glitch Pop ", 3: "Nu Jazz", 4: "Drumfunk", 5: "Bitpop", 6: "Latin Pop", 7: "Carnatic"} into this ==>>>> [{id: 1 name ...

Converting a JSON array stored in a local file to a TypeScript array within an Angular 5 project

I'm currently working on developing a web app using Angular 5. My JSON file has the following structure: [ { "id": 0, "title": "Some title" }, { "id": 1, "title": "Some title" }, ... ] The JSON file is store ...