I'm trying to write my database-data to a JSON. It works when I do not use the loop.
Then I get: TypeError: first argument must be a string or Buffer
I'm using the mysql npm package.
con.query('SELECT * FROM mydb.orders_view;', function(err, rows, fields) {
if (err) {
res.status(500).json({ result: 'Error' })
}
for (var i = 0; i < rows.length; i++) {
res.write(
{
time: date,
Order: [{
OrderedBy: rows[i]['OrderedBy']
}]
}
);
}
res.end();
});
});