To retrieve last inserted id with Node MySQL, we use the insertedId
property.
For instance, we write
connection.query(
"INSERT INTO posts SET ?",
{ title: "test" },
(err, result, fields) => {
if (err) throw err;
console.log(result.insertId);
}
);
to call query
with a callback that gets the result.insertId
property to get the ID of the last inserted item.