I have a problem in Node.js i have build my own modul, to handle a kind of stuff, in this modul i have a function getList() where i can get a inputs to my config.
my source code is this:
var config = {
'limit' : 0
};
var dict = [];
exports.getList = function(db, conf) {
db.query("SELECT id, title FROM animal a " + (config.limit > 0 ? " LIMIT " + config.limit : "" ), function(err, rows, fields) {
if(err) {
console.log(err);
}
for(var key in rows) {
var row = rows[key];
//
dict.push({
'title' : 'Buster',
'animal' : 'Dog',
'age' : '12',
'photo' : 'https://placeholdit.imgix.net/~text?txtsize=24&txt=260×200&w=260&h=200'
});
});
console.log(dict);
console.log(config);
return dict;
}
The problem is when i start my application up and first time i call this script the dict its empty, second time its have 3 rows from my database, and every time i reload the pages its add 3 more to it.
i have trying to find out how i handle this issue whiteout a aware hope somebody can help me here, thanks a lot.