I have two separate Folders.
/controller/anbieter.js
function getAnbieterById(req, res) {
var userid = parseInt(req.params.id);
let anbieter = Anbieter.findById(userid);
res.send(anbieter);
};
/model/anbieter.js
findById(id){
let sql = `SELECT * FROM Anbieter WHERE Anbieter_id= ${id};`;
db.query(sql);
}
I am getting error that Anbieter.findById is not a function
The way you are calling Anbieter.findById(userid); is supposed to be defined as a static method. so instead of findById use
class Anbieter{
static findById(){
// your logic goes here
}
}
And, I think you would like to use async with your functions since db queries are asynchronous.
export function findById and import in this function /controller/anbieter.js .