I am looking to bind a variable to my request object so when the callback is made I have access to this variable.
Here is the library: https://github.com/request/request
Here is my code.
var request = require('request');
for (i = 0; i < cars.length; i++) {
request({
headers: { 'Content-Type': 'application/json'},
uri: 'https://example.com',
method: 'POST',
body: '{"clientId": "x", "clientSecret": "y"}'
},
function(err, res, body){
// I want to put the correct i here.
// This outputs cars.length almost everytime.
console.log(i);
});
}