I have the following module that I use to connect to my database:
module.exports = {
var sequelize = new Sequelize('db', 'rt', 'pw', {
host: "localhost",
port: 3306,
socketPath: '/var/run/mysqld/mysqld.sock',
dialect: 'mysql'
})
}
and then in the main file
var configDB = require('./config/database.js');
But, unfortunately, this leads to the following error:
/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)
Am I using the function exportsincorrectly? This error occurs for each object in the export module.
EDIT: the following returns cannot call method .authenticate of undefined, although the module seems to export without errors.
configDB.sequelize
.authenticate()
.complete(function(err) {
if (!!err) {
console.log('Unable to connect to the database:', err)
} else {
console.log('Connection has been established successfully.')
}
})
source
share