Node中使用MySQL报错:

TypeError: Cannot read property 'query' of undefined
at /Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/models/user.js::
at Handshake.onConnect [as _callback] (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/Pool.js::)
at Handshake.Sequence.end (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/protocol/sequences/Sequence.js::)
at Handshake.ErrorPacket (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/protocol/sequences/Handshake.js::)
at Protocol._parsePacket (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/protocol/Protocol.js::)
at Parser.write (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/protocol/Parser.js::)
at Protocol.write (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/protocol/Protocol.js::)
at Socket.<anonymous> (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/Connection.js::)
at emitOne (events.js::)
at Socket.emit (events.js::)

解决办法:

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

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

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

解决办法:

app.js,session 加两个参数:

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

Node中使用MySQL报错:TypeError: Cannot read property 'query' of undefined的更多相关文章

  1. VUE.JS 使用axios数据请求时数据绑定时 报错 TypeError: Cannot set property 'xxxx' of undefined 的解决办法

    正常情况下在data里面都有做了定义 在函数里面进行赋值 这时候你运行时会发现,数据可以请求到,但是会报错 TypeError: Cannot set property 'listgroup' of ...

  2. vue表单校验提交报错TypeError: Cannot read property 'validate' of undefined

    TypeError: Cannot read property 'validate' of undefined at VueComponent.submitForm (plat_users.html: ...

  3. 使用webpack命令打包时,报错TypeError: Cannot read property 'presetToOptions' of undefined的解决办法

    我只安装了webpack,没有安装webpack-cli,第一次输入webpack打包时,提示 One CLI for webpack must be installed. These are rec ...

  4. vue报错TypeError: Cannot read property 'protocol' of undefined

    错误信息如下所示: isURLSameOrigin.js?3934:57 Uncaught (in promise) TypeError: Cannot read property 'protocol ...

  5. react报错 TypeError: Cannot read property 'setState' of undefined

    代码如下: class test extends Component { constructor(props) { super(props); this.state = { liked: false ...

  6. vue报错TypeError: Cannot read property '$createElement' of undefined

    报错截图: 这个错误就是路由上的component写成了components

  7. Node.js报错TypeError: Cannot read property 'isDirectory' of undefined

    截图如下: 原因如下:记住"./uploads" 后要加一个/ fs.stat("./uploads/" + files[i], function(err, s ...

  8. VUE - 使用axios数据请求时数据绑定时 报错 TypeError: Cannot set property 'xxxx' of undefined 的解决办法

     created() {     var that=this     axios.get('http://jsonplaceholder.typicode.com/todos')     .then( ...

  9. JS报错:Cannot read property 'type' of undefined

    在做图片上传功能的时候,遇到了JS无法识别图片type的问题,在使用过程中是没有问题的,但是不知道为什么浏览器的Console报这个错误: Uncaught TypeError: Cannot rea ...

随机推荐

  1. 【Java】用五种语言写数组(用于自己学习)

    C语言 #include<stdio.h> int main() { ] = {, , , , , , , , , }; int i; ;i<;i++) printf("% ...

  2. django Error: HINT: Add or change a related_name argument to the definition for 'UserProfile.groups' or 'User.groups'.

    # 解决方案: 因自己重新封装user为UserProfile故在 settings中 添加自己的

  3. TG2

    1,什么滑动窗口? 2,这人讲的不行还是我的问题.. 3,搞得我都想睡觉了 4,1904,不停扫,输出最高的高度 一个差分的过程,先加上再减去,但是要维护一个最值 什么动态开点(只能用线段树并且内存很 ...

  4. [NOI2008]假面舞会 (搜索+gcd)

    题意 LuoguP1477 题解 对于每一条边(u,v)(u,v)(u,v),建两条边(u→v,1),(v→u,−1)(u\to v,1),(v\to u,-1)(u→v,1),(v→u,−1).跑b ...

  5. 使用注解方式实现 AOP和IoC

    使用注解方式实现AOP和IoC IOC和DI的注解 IOC: @Component:实现Bean组件的定义 @Repository:用于标注DAO类,功能与@Component作用相当 @Servic ...

  6. 005_simulink建立条件子系统

    1. 条件执行子系统 a)  使能子系统:是控制信号大于零时执行的子系统.在控制信号穿越零点由负变正的时步点上,使能子系统开始执行.只要子系统的控制信号保持正值,使能子系统就会保持在执行的状态 b)  ...

  7. 062_判断用户输入的是 Yes 或 NO

    #!/bin/bashread -p "Are you sure?[y/n]:" surecase $sure iny|Y|Yes|YES)     echo "you ...

  8. 模拟I2C协议学习点滴之程序相关定义

    由于主机和从机都会给数据线SDA发信号,比如主机先给SDA发送数据后,从机收到数据后发送应答信号将SDA拉低,故SDA类型设定为inout.而DATA设定为inout类型,是起到校验通信的作用(后续的 ...

  9. hdu 3 * problem

    hdu 6182 给出 $n$ 求 $\sum_{i = 1} ^ {\infty} (i * i <= n)$ 暴力枚举 hdu 6186 给出 $n$ 个数 $1e6$ 次询问,每次询问这 ...

  10. Android工程的合并

    http://www.xuanyusong.com/archives/3395 1.游戏包名( 类似 com.xx.xxx ) Android应用程序只能有一个包名,如果两个游戏包名一样,那么后者安装 ...