Avatar
the world's not perfect but it's not that bad

Today's Node.js progress🥱

今日nodejs进度🥱

Avatar
the world's not perfect but it's not that bad

I think I hit a snag with nodejs+mysql today. When executing a query, the data likely hasn't returned yet, so the code below executes first, which causes the send method to be called multiple times, leading to a headers issue. I don't know how to solve it for now. I'm following the video, and the video works, but I keep getting an error.😌

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

    at new NodeError (internal/errors.js:322:7)

    at ServerResponse.setHeader (_http_outgoing.js:561:11)

    at ServerResponse.header (D:\Project\nodejs\node_modules\express\lib\response.js:776:10)

    at ServerResponse.send (D:\Project\nodejs\node_modules\express\lib\response.js:170:12)

    at ServerResponse.json (D:\Project\nodejs\node_modules\express\lib\response.js:267:15)

    at ServerResponse.send (D:\Project\nodejs\node_modules\express\lib\response.js:158:21)

    at Query.<anonymous> (D:\Project\nodejs\77.api_server\router_handler\user.js:71:20)

    at Query.<anonymous> (D:\Project\nodejs\node_modules\mysql\lib\Connection.js:526:10)

    at Query._callback (D:\Project\nodejs\node_modules\mysql\lib\Connection.js:488:16)

    at Query.Sequence.end (D:\Project\nodejs\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24) {

  code: 'ERR_HTTP_HEADERS_SENT'

}

今日nodejs+mysql应该是遇到一个坑,执行query的时候,数据应该还没有回来,然后先执行下边的代码,导致执行多次send,然后就是请求头问题,暂时不知道怎么解决,跟着视频敲的,视频没问题,到我这就不行了😌

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

    at new NodeError (internal/errors.js:322:7)

    at ServerResponse.setHeader (_http_outgoing.js:561:11)

    at ServerResponse.header (D:\Project\nodejs\node_modules\express\lib\response.js:776:10)

    at ServerResponse.send (D:\Project\nodejs\node_modules\express\lib\response.js:170:12)

    at ServerResponse.json (D:\Project\nodejs\node_modules\express\lib\response.js:267:15)

    at ServerResponse.send (D:\Project\nodejs\node_modules\express\lib\response.js:158:21)

    at Query.<anonymous> (D:\Project\nodejs\77.api_server\router_handler\user.js:71:20)

    at Query.<anonymous> (D:\Project\nodejs\node_modules\mysql\lib\Connection.js:526:10)

    at Query._callback (D:\Project\nodejs\node_modules\mysql\lib\Connection.js:488:16)

    at Query.Sequence.end (D:\Project\nodejs\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24) {

  code: 'ERR_HTTP_HEADERS_SENT'

}