I have done one project where I used one callback so far, but with a bigger code base I already have chaos in it. I would like to move on to something new, specifically on async functions.
I'm using an oop pattern, so I'd like this to be implemented right into the oop. The problem is that, I've never done this before and I don't know how to do it. I have some basic code with a callback. Could anyone change this to an async function, please?
server.js
const object = require("./object");
new object(userID).name((data) => {
console.log(data);
});
object.js
module.exports = class{
constructor(userID){
this.id = userID;
}
name(callback){
mysqli.query("SELECT meno FROM uzivatelia WHERE id='"+ this.id +"'", (err, user) => {
callback(user[0].meno);
});
}
}