Error with query on nodejs

Hi, guys i have this code:

app.get("/tema/:search", (req, res, next) => {
    res.setHeader("Content-Type", "application/json; charset=utf-8");
    var params = [req.params.search]
    //var sql = 'SELECT * FROM Topics where topic like ' + keyword;
    var sql = `SELECT * FROM Topics WHERE topic LIKE "%${params}%"`;
    db.all(sql,params, function(rows, err) {
        console.log(sql,params);

        rows.forEach(function(row) {
        console.log(row.id + ": " + row.topic);
        var temp = row.topic;
        res.write(temp);
        });
    });
});

but got the error:

TypeError: rows.forEach is not a function

if i use the ID for call the title of the category this works, so the problem is on the LIKE concatenation, anyone has experience on this?

thanks !

I’m a bit confused…

  1. what kind of data you want your server to respond with? You’re writing strings in parts, not json. Also you would need to add res.end() to close connection.
  2. if you’re sending only results from topic column, why not SELECT topic FROM Topics...

Re TypeError, the nature of error tells me you might have flipped arguments in your callback