Reputation: 91
I'm building an employee tracker application using node and mysql and I keep getting this error when I run my code in the command line: 'Ignoring invalid configuration option passed to Connection: username. This message is currently a warning, but in future versions of MYSQL2, an error will be thrown if you pass an invalid configuration option to a Connection'
This is my code in JS for the connection. My password is in an .env file
// Connects to database + .env for password privacy
const connection = mysql.createConnection({
host: "localhost",
username: "root",
password: process.env.DB_PASS,
port: PORT,
database: "employee_tracker",
}
);
connection.connect((err) => {
if (err) {
console.log("Error with connection")
} else {
console.log("Connected to Employee Tracker")
}
// Calls Starting Fx that begins program
init();
})
app.listen(PORT, () =>
console.info(`Example app listening at http://localhost:${PORT}`)
);
I'm not really sure what I'm doing wrong. Per a previous stack overflow answer, I attempted to change my username to 'user' with no success. Any help appreciated. Thanks!
Upvotes: 0
Views: 3147
Reputation: 1350
The correct key is user
not username
see docs
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: process.env.DB_PASS,
port: process.env.DB_PORT || 3306,
database: 'employee_tracker',
}
);
Also, you have defined port
which I'm not certain is supported option in MYSQL2
but is in mysqljs/mysql
. However, you currently have it set to a variable PORT
which you are also using as a variable for the port your app will listen on. Both services can not run on the same port. I've updated my example accordingly but you should review and do something similar.
Upvotes: 1