Node.JS: How to pass variables to asynchronous callbacks? [duplicate]
This question already has an answer here: JavaScript closure inside loops – simple practical example 43 answers I'm sure my problem is based on a lack of understanding of asynch programming in node.js but here goes. For example: I have a list of links I want to crawl. When each asynch request returns I want to know which URL it is for. But, presumably because of race conditions, each request returns with the URL set to the last value in the list. var links = ['http://google.com', 'http://yahoo.com']; for (link in links) { var url = links[link]; require('request')(url, function() { console.log