Node JS mysql2 call stored procedure

116 Views Asked by At

I am using node JS and express and Mysql database on the backend. I originally used MS Sql Server, but converting to Mysql now. I am struggling to get a stored procedure to work when calling from node JS.

My original MS Sql Server code returned the correct data, but the Mysql seems to return undefined:

let email = req.body.email;
let psw = req.body.psw;

await pool.connect();
const data = [
    email
];

// Mysql
const [result1] = await mysqldb.pool.query('CALL Read_User_Short_ByEmail_SP(?)', data);
const users1 = result1.recordset;
console.log('USER1 = ' + users1[0].UserID);

// MS Sql Server
const result = await pool.request()
    .input('Email', email)
    .execute('Read_User_Short_ByEmail_SP');
const users = result.recordset;
console.log('USER = ' + users[0].UserID);

What am I missing here? I am using the npm mysql2 package.

0

There are 0 best solutions below