Node Error : Cannot set headers after they are sent to the client
问题原因
在请求时 ,才会出现这种报错,一定是因为,浏览器请求一次之后,服务器后台返回了两次或以上的响应
解决办法
清理多余次数响应;每次响应后立马return掉函数
router.get('/',function(req,res,next){
Goods.find({},function(err,doc){
if(err){
res.json({
status:'1',
msg:err.message
});
}else{
res.json({
status:'0',
msg:'',
result:{
count:doc.length,
list:doc
}
})
}
})
})