The problem is that the value of key
in the closure is the same for all your routes (the value in the last iteration).
This should help explain how to create a new closure with a separate value in each one: http://www.mennovanslooten.nl/blog/post/62
Something like this should help:
for (key in data) {
console.log(key + "---" + '/' + data[key]);
(function(key1) {
app.get('/' + data[key1], function(req, res) {
console.log(data[key1]);
});
}
)(key);
}
In the above code, key1
keeps a different value for each iteration in a separate closure.