Node中使用MySQL报错:TypeError: Cannot read property 'query' of undefined

Node中使用MySQL报错:

TypeError: Cannot read property 'query' of undefined
    at /Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/models/user.js:23:15
    at Handshake.onConnect [as _callback] (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/Pool.js:58:9)
    at Handshake.Sequence.end (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/protocol/sequences/Sequence.js:88:24)
    at Handshake.ErrorPacket (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/protocol/sequences/Handshake.js:132:8)
    at Protocol._parsePacket (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/protocol/Protocol.js:279:23)
    at Parser.write (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket. (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/Connection.js:103:28)
    at emitOne (events.js:115:13)
    at Socket.emit (events.js:210:7)

解决办法:

如下图所示将host改为localhost即可.

Node中使用MySQL报错:TypeError: Cannot read property 'query' of undefined_第1张图片

使用Express-session出现以下问题:

express-session deprecated undefined resave option; provide resave option app.js:27:9
express-session deprecated undefined saveUninitialized option; provide saveUninitialized option app.js:27:9

解决办法:

app.js,session 加两个参数:

app.use(session({
  resave: true,  // 新增
  saveUninitialized: true,  // 新增
  secret: config.secret,
}));

 

转载于:https://www.cnblogs.com/pengsi/p/7878795.html

你可能感兴趣的:(Node中使用MySQL报错:TypeError: Cannot read property 'query' of undefined)