Try to search your question here, if you can't find : Ask Any Question Now ?

Is there a way of not hard coding sql queries in my express app?

HomeCategory: stackoverflowIs there a way of not hard coding sql queries in my express app?
Avatarkundan asked 5 months ago

So I am making an express app for a project and I am using mysql as the db, I had previously hard coded my sql queries in my code, but it is bad practice to do so according to my teacher, so I was looking for a way in which I don’t have to hard code.

I have tried queries like find and findAll using mongoose, I am looking for something similar.

app.get("/shops/:id",function(req,res){
    var id = req.params.id;

    connection.query('SELECT * FROM `menuItems` WHERE shop_id =?',[id],function(error,results,fields) {
        console.log(results);
        res.json(JSON.stringify(results));
    })
});

I don’t want to hard code my queries as I have in the above code snippet.

Kindly help me get a way for not hard coding sql queries in my app. Thanks in advance.

1 Answers
Best Answer
AvatarMikhail answered 5 months ago
Your Answer

15 + 13 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com