我有以下的模塊,我使用連接到我的數據庫:意外標識使用module.exports(Node.js的)時
module.exports = {
var sequelize = new Sequelize('db', 'rt', 'pw', {
host: "localhost",
port: 3306,
socketPath: '/var/run/mysqld/mysqld.sock',
dialect: 'mysql'
})
}
,然後在主文件,
var configDB = require('./config/database.js');
但不幸的是這將返回以下錯誤:使用exports
功能INCOR我
/config/database.js:3
var sequelize = new Sequelize('db', 'rt', 'pw', {
^^^^^^^^^
SyntaxError: Unexpected identifier
at exports.runInThisContext (vm.js:69:16)
at Module._compile (module.js:432:25)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:349:32)
at Function.Module._load (module.js:305:12)
at Module.require (module.js:357:17)
at require (module.js:373:17)
at Object.<anonymous> (/server.js:14:16)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
上午rectly?導出模塊中的每個對象都會發生此錯誤。
編輯:以下返回cannot call method .authenticate of undefined
,即使該模塊似乎導出沒有錯誤。
configDB.sequelize // connect to our database
.authenticate()
.complete(function(err) {
if (!!err) {
console.log('Unable to connect to the database:', err)
} else {
console.log('Connection has been established successfully.')
}
})
更新我的答案,以幫助澄清數據如何傳遞。 – Jason