5-6节 查询blog列表报错
来源:6-6 API对接mysql(博客列表)
浩浩吃
2019-04-16
[Running] node "e:
odejsprojectlog-1inwww.js"
e:
odejsprojectlog-1
ode_modulesmysqllibConnectionConfig.js:12
this.host = options.host || ‘localhost’;
^
TypeError: Cannot read property ‘host’ of undefined
at new ConnectionConfig (e:
odejsprojectlog-1
ode_modulesmysqllibConnectionConfig.js:12:37)
at Object.createConnection (e:
odejsprojectlog-1
ode_modulesmysqlindex.js:13:34)
at Object. (e:
odejsprojectlog-1srcdbmysql.js:6:19)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
但在con直接写这个却能连接数据库const con = mysql.createConnection({
host:‘localhost’,
user:‘root’,
password:‘011310’,
port:‘3306’,
database:‘myblog’
})
但引用const con = mysql.createConnection(MYSQL_CONF)就会出错误
2回答
-
浩浩吃
提问者
2019-04-16
MYSQL_CONF打印出来也是未定义的。。。
00 -
浩浩吃
提问者
2019-04-16
好吧 老师 我最终发现打印
const env = process.env.NODE_ENV //环境参数
env打印出来是未定义的 然后我就不知道怎么解决了
022019-04-16
相似问题