So here is the controller's code which I am using to handle password generation process. There is a table called as passwordrecovery which has the following columns:-
- id
- uuid
- isActive
Code
File: db.js
const mysql = require("mysql2");
const connectionPool = mysql.createPool({
user: "root",
database: "expensetracker",
host: "localhost",
password: process.env.MYSQL_PASSWORD,
});
module.exports = connectionPool;
File- users.js
const path = require("path");
const db = require("../database/db");
exports.passwordGenerator = async (req, res, next) => {
var id = req.query.id;
console.log(id);
await db.execute(
"SELECT uuid, isActive FROM passwordrecovery WHERE id = ?",
[id],
(err, results) => {
if (err) {
console.log(err);
res.status(500).send("SERVER ERROR");
} else {
//console.log(results);
const response = results[0];
const isActive = parseInt(response.isActive);
if (isActive == 1) {
db.execute(
"UPDATE passwordrecovery SET uuid = ?, isActive = 0 WHERE id = ?",
[null, id],
(err, results) => {
if (err) {
console.log(err);
return res.status(500).send("SERVER ERROR");
} else {
console.log(results);
return res
.status(200)
.sendFile(
path.join(
__dirname,
"..",
"views",
"password-reset-form.html"
)
);
}
}
);
} else {
res.status(408).send("SESSION EXPIRED");
}
}
}
);
};
Error Message
undefined
TypeError: Bind parameters must not contain undefined. To pass SQL NULL specify JS null
at D:\Projects\Expense Tracker\Backend\node_modules\mysql2\lib\connection.js:659:17
at Array.forEach (<anonymous>)
at PoolConnection.execute (D:\Projects\Expense Tracker\Backend\node_modules\mysql2\lib\connection.js:651:22)
at D:\Projects\Expense Tracker\Backend\node_modules\mysql2\lib\pool.js:172:14
at D:\Projects\Expense Tracker\Backend\node_modules\mysql2\lib\pool.js:45:37
at processTicksAndRejections (node:internal/process/task_queues:78:11)
I was expecting that this express js server would return that html(password-reset-form.html) file which it does, here is response from server but it also console logs this error message. I don't know what to, tried my best to resolve myself, read some blogs, googled some stuff but still could not solve this error!