Cannot set headers after they are sent to the client
D:\le\node_modules\mysql\lib\protocol\Parser.js:
throw err; // Rethrow non-MySQL errors
^ Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the cli
ent
at ServerResponse.setHeader (_http_outgoing.js::)
at ServerResponse.header (D:\le\node_modules\express\lib\response.js::
)
at ServerResponse.send (D:\le\node_modules\express\lib\response.js::
)
at ServerResponse.json (D:\le\node_modules\express\lib\response.js::
)
at ServerResponse.send (D:\le\node_modules\express\lib\response.js::
)
at D:\le\routes\cart.js::
at D:\le\models\cart.js::
at Query._callback (D:\le\models\db.js::)
at Query.Sequence.end (D:\le\node_modules\mysql\lib\protocol\sequences\Se
quence.js::)
at Query.ErrorPacket (D:\le\node_modules\mysql\lib\protocol\sequences\Que
ry.js::)
npm ERR! code ELIFECYCLE
npm ERR! errno
npm ERR! letao@0.0. start: `node ./bin/www`
npm ERR! Exit status
npm ERR!
npm ERR! Failed at the letao@0.0. start script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above. npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\administrator\AppData\Roaming\npm-cache\_logs\--28T11_00_46_4
81Z-debug.log D:\letao>
注意其中at Query._callback (D:\le\models\db.js:44:22)找到models\db.js44行
pool.getConnection(function(err, connection) {
if (err) {
// callback(err);
return callback(err);
}
connection.query(sqlStr, params, function(err, rows) {
if (err) {
// callback(err);
return callback(err);
}
connection.release();
callback.apply(null, arguments);//报错行44
});
});
在callback(err)前加return上述错误解决了。具体原因详见参考文章。
参考文章:
https://stackoverflow.com/questions/7042340/error-cant-set-headers-after-they-are-sent-to-the-client
https://cnodejs.org/topic/53774ffecbcc396349ca1155
https://cnodejs.org/topic/5635fed78c67728402553324
https://stackoverflow.com/questions/27658997/cant-set-headers-after-they-are-sent-on-express
Cannot set headers after they are sent to the client的更多相关文章
- Nodejs实现简单的反向代理
var http = require('http'), httpProxy = require('http-proxy'); // 新建一个代理 Proxy Server 对象 var proxy = ...
- c# WebClient文件下载
public void HttpDownload(string url, string path, ResourceType type) { using (var client = new WebCl ...
- webclient的简单实用
这是我在项目中调用别人写好的接口口是使用的1.简单的url传参 List<ArticleModel> result = new List<ArticleModel>(); st ...
- 通过rpc访问比特币核心钱包
开发环境和工具 1. window 10 64 2. 比特核心钱包:bitcoin core 64 配置过程 1. 下载比特币核心钱包,下载链接https://bitcoin.org/en/downl ...
- 用任意语言与WebService进行交互
using System; using System.Web.Services; using YY.SmsPlatform.Common.Objects; using YY.SmsPlatform.C ...
- .net WebClient发送请求实例:
public static Main(string [] ager) { WebClient client = new WebClient(); client.Headers.Clear(); cli ...
- webapi 中使用 protobuf
相比json来说,好处是速度更快,带宽占用更小.其效果大致等于json+Gzip. 在webapi中使用protobuf的方法为: 引用nuget包 Install-Package protobuf- ...
- Getting Started with ASP.NET Web API 2 (C#)
By Mike Wasson|last updated May 28, 2015 7556 of 8454 people found this helpful Print Download Com ...
- WebClient 使用
--post 请求 public static string PostMsg(Guid orgid, int page, int rows) { System.N ...
随机推荐
- Create an OData v4 Endpoint Using ASP.NET Web API 2.2(使用ASP.NET Web API 2.2创建OData v4端点)
开放数据协议Open Data Protocol(OData)是web的一种数据存取协议,OData通过设置CRUD操作(Create创建.Read读取.Update更新,Delete删除)提供一种统 ...
- mongodb学习之:mongo安装以及远程访问
在linux下通过apt-get install mongo的方式一键式安装mongo 安装后mongo的配置文件位于/etc/mongodb.conf. 里面有mongo的各项配置,文件内容如下:重 ...
- Hibernate主要查询方式
1.hql查询 1.1 无参数的hql查询 1.2 带参的hql查询(分为问号占位和字符占位两种) Ps: 绑定各种类型的参数时用setParameter()绑定参数,如封装方法后用不定参数时循环绑定 ...
- 常用的Css命名方式
常用的Css命名方式: CSS命名规范: 1.文件命名规范 全局样式:global.css: 框架布局:layout.css: 字体样式:font.css: 链接样式:link.css: 打印样式:p ...
- 常见的LINUX发行版安装libiconv库方法
今天编译程序,发现程序报错,如下 cannot find -liconv collect2: ld returned 1 exit status 或者 undefined reference to ` ...
- web安全字体
webfont解剖 Unicode字体可以包含数以千计字形 有四个字体格式: WOFF2, WOFF, EOT, TTF 一些字体格式需要使用GZIP压缩 一个web字体是字形的集合,且每个字形是一个 ...
- vertical-align 的理解
1.vertical-align 属性和值列表
- Linux-正则表达式与三剑客
1 固化命令文件 登录时执行文件的顺序 /etc/profile /etc/profile.d ~/.bash_profile ~/.bashrc /etc/bashrc 非登录shell ~/.ba ...
- package-info.java到底是什么
发现距离上一次在这里写博客已经三个多月了...说好的笔耕不辍呢=.= Anyway,今天(确切说是昨天晚上)在code review中被组里的QA II问到在一个叫做package-info.java ...
- SPOJ(后缀数组求不同子串个数)
DISUBSTR - Distinct Substrings Given a string, we need to find the total number of its distinct subs ...