I have an ordinary
var express = require(\'express\')
Node express www page, using session, pug, etc as usual. My db calls
var
If you're trying to use MySQL with Nodejs, the module you should be looking for is mysql2
rather than mysql
.
mysql2
provides a promise based approach and is a much refined version of mysql
module for nodejs.
For example, for executing a query,
mysql
con.query(sql_query, (err, rows, field)=>{ //some code here }
mysql2
, you can use the async approach as well as promise approach. Also, prepared statements in mysql2 are more easier than mysql.//async approach
class A {
static async fn(sql, params){
const [data] = await con.execute(sql, [params]);
return data;
}
}
//promise approach remains same as **mysql** itself.
Here's the documentation for mysql2 & more docs