Node server response error: process.nextTick(function(){throw err;});

wsfuller

So I have a very simple application that I'm building to practice with Mongo, Express, and Node.

I'm getting an error process.nextTick(function(){throw err;});

The error seems to occur when I try to use res.json(docs) in the success conditional during the GET request. However, I can console.log(docs) and see the JSON.

Development Environment

  • Windows 7 64-bit
  • Mongo 3.2
  • Node 5.6

package.json:

...
  "dependencies": {
    "body-parser": "^1.15.0",
    "express": "^4.13.4",
    "mongojs": "^2.3.0"
  }
...

app.js (api):

var express = require('express');
var app = express();
var mongojs = require('mongojs');
var db = mongojs('catalog', ['products']);

app.get('/', function(req,res){
  res.send('It works, indeed'); // this is working
});

app.get('/products', function(req,res){
  res.send('Products Works'); // this is displaying correctly on the page
  console.log('Fetching products');
  db.products.find(function(err,docs){
    if(err){
      res.send(err);
    }
    else{
      console.log('Sending Products');
      console.log('response docs', docs); // returns the correct JSON
      res.json('stuff sent'); // Throws error
    }
  });
});

app.listen(3000);
console.log('Server is running on port 3000');

I'm not sure why this is failing. I'm able to console log the JSON so know that the data is there and available in the response. Just not sure why the res.json(docs) doesn't work.

eljefedelrodeodeljefe

You are calling the implicit callback twice

res.send('Products Works'); // this is displaying correctly on the page

and

res.json(docs);

remove either (probably the first one)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Gulp error internal/child_process.js:298 throw errnoException(err, 'spawn'); Error: spawn EACCES

From Dev

Throw sqlite insert error in node application without stopping node server

From Dev

GULP Error internal/child_process.js:298 throw errnoException(err, 'spawn');

From Dev

process took long then gives error "This page isn’t working <ssh-server-ip-address> didn’t send any data. ERR_EMPTY_RESPONSE"

From Dev

throw error code with 'return next(err);'

From Dev

ES6 syntax : what is this an error : .catch(err => throw err);

From Dev

ERR_EMPTY_RESPONSE error using multiparty package in Node.js

From Dev

'process.nextTick(function() { throw err; })' - Undefined is not a function (mongodb/mongoose)

From Dev

node js error on response methods between server and client

From Dev

module.js:338 throw err in node.js

From Dev

nodejs error: module.js:340 throw err;

From Dev

Node.js app giving ERR_EMPTY_RESPONSE

From Dev

Proxy request with Node.js: net::ERR_EMPTY_RESPONSE

From Dev

Send KillAll to multiple node process and wait response

From Dev

Node.js and server process

From Dev

pyodbc does not throw on SQL Server error

From Dev

ftplib capture and process ftp server response code

From Dev

node child process jasmine error

From Dev

node-sass throw error when upgrade node to 4.0.0

From Dev

getting this net::ERR_EMPTY_RESPONSE error in browser

From Dev

net::ERR_EMPTY_RESPONSE error on DELETE Method in Angular 4?

From Dev

Node.js - events.js:154 throw err write EPIPE; Program Crashing

From Dev

Get server response with AJAX error?

From Dev

Get server response with AJAX error?

From Dev

Node.js with Express - throw Error vs next(error)

From Dev

Node.js server + SSL = ERR_CONNECTION_CLOSED

From Dev

Node server, socket, request and response timeouts

From Dev

No response on typing 'node server.js'

From Dev

React POST to Node Server and handle JSON response

Related Related

  1. 1

    Gulp error internal/child_process.js:298 throw errnoException(err, 'spawn'); Error: spawn EACCES

  2. 2

    Throw sqlite insert error in node application without stopping node server

  3. 3

    GULP Error internal/child_process.js:298 throw errnoException(err, 'spawn');

  4. 4

    process took long then gives error "This page isn’t working <ssh-server-ip-address> didn’t send any data. ERR_EMPTY_RESPONSE"

  5. 5

    throw error code with 'return next(err);'

  6. 6

    ES6 syntax : what is this an error : .catch(err => throw err);

  7. 7

    ERR_EMPTY_RESPONSE error using multiparty package in Node.js

  8. 8

    'process.nextTick(function() { throw err; })' - Undefined is not a function (mongodb/mongoose)

  9. 9

    node js error on response methods between server and client

  10. 10

    module.js:338 throw err in node.js

  11. 11

    nodejs error: module.js:340 throw err;

  12. 12

    Node.js app giving ERR_EMPTY_RESPONSE

  13. 13

    Proxy request with Node.js: net::ERR_EMPTY_RESPONSE

  14. 14

    Send KillAll to multiple node process and wait response

  15. 15

    Node.js and server process

  16. 16

    pyodbc does not throw on SQL Server error

  17. 17

    ftplib capture and process ftp server response code

  18. 18

    node child process jasmine error

  19. 19

    node-sass throw error when upgrade node to 4.0.0

  20. 20

    getting this net::ERR_EMPTY_RESPONSE error in browser

  21. 21

    net::ERR_EMPTY_RESPONSE error on DELETE Method in Angular 4?

  22. 22

    Node.js - events.js:154 throw err write EPIPE; Program Crashing

  23. 23

    Get server response with AJAX error?

  24. 24

    Get server response with AJAX error?

  25. 25

    Node.js with Express - throw Error vs next(error)

  26. 26

    Node.js server + SSL = ERR_CONNECTION_CLOSED

  27. 27

    Node server, socket, request and response timeouts

  28. 28

    No response on typing 'node server.js'

  29. 29

    React POST to Node Server and handle JSON response

HotTag

Archive