节点服务器响应错误: process.nextTick(function(){throw err;});.
Node server response error: process.nextTick(function(){throw err;});
所以我有一个非常简单的应用程序,我正在构建它来练习Mongo,Express和Node。
我收到错误process.nextTick(function(){throw err;});
当我尝试在 GET 请求期间以成功条件使用res.json(docs)
时,似乎发生了错误。但是,我可以console.log(docs)
并看到 JSON。
开发环境
- 视窗 7 64 位
- 蒙戈 3.2
- 节点 5.6
package.json:
...
"dependencies": {
"body-parser": "^1.15.0",
"express": "^4.13.4",
"mongojs": "^2.3.0"
}
...
应用程序.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');
我不确定为什么这会失败。我能够控制台记录 JSON,因此知道数据在那里并且在响应中可用。只是不确定为什么res.json(docs)
不起作用。
您正在两次调用隐式回调
res.send('Products Works'); // this is displaying correctly on the page
和
res.json(docs);
删除任何一个(可能是第一个)
相关文章:
- 安装节点6后出错,npm ERR!无效版本:1.0.5beta
- system.err风格的控制台以javascript打印
- AngularJS:使用ng-show/hide动态维护下拉列表的3种状态(InProgress、Success、Err
- npm ERR!安装无法't在mac上读取依赖项
- $provide.decorator$controller return throw undefined不是angula
- 当“new constructor()”与mocha和chai一起使用时,我如何断言throw
- 通过带有err,value签名的回调创建promise
- 为什么我们必须在es6箭头函数中用括号包装throw
- 在 Mocha 中,返回将被拒绝的承诺与调用 done(err) 的效果不同
- Jquery iterate throw json
- 节点服务器响应错误: process.nextTick(function(){throw err;});.
- .NET 4上的ASP.NET导致IE11 throw _doPostBack是未定义的javascript错误
- Use coffeescript/javascript 'throw error' or 'th
- res://ieframe.dll/acr-err 在 Java 6 上的 IE 11 //Windows 8/8.1/
- net::ERR CONTENT LENGTH MISMATCH in Chrome with Jboss WildFl
- Heroku,节点npm ERR!argv”/app/.heroku/note/bin/node”"/app/.
- Aurelia npm install: tons of "gyp ERR"
- 在Javascript表达式中使用throw
- 在JavaScript中,“throw”之后需要“return”吗
- ES6生成器:从iterator.throw(err)中跟踪堆栈错误