module request global variable (inside request module)

19 views
Skip to first unread message

jeg

unread,
Mar 27, 2016, 5:12:21 PM3/27/16
to nodejs
Hi,

I use un array with 2 values string1 and string2

string1 is outside request (call before request module)
string2 inside request module

How can i get my variable string2  using module request

I try, global, it doesn't work well

Thanks for you help

Eric

...

for (var j = 0, len = arr.length; j < len; j++) {
...
var obj2 = JSON.parse(arr[j]) ;
console.log(obj2.string1 + ' : ' + obj2.string2) ;

// string1 string2 are OK
// string1 is used to build the url, OK 
...

request(string1, function (error, response, html) {

// request use string1, OK

  if (!error && response.statusCode == 200) {
    var $ = cheerio.load(html);
    $('td.event-favourite').each(function(i, element){
      var a = $(this);


...

var z1 = 'test :' + string2

// string2 
string2 contains the last value
 

Kevin "Ingwie Phoenix" Ingwersen

unread,
Mar 27, 2016, 8:42:20 PM3/27/16
to nod...@googlegroups.com
If you were providing an example it would be easier to lend a hand…

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/9d2d3659-0d37-449d-b79f-8184cfdcd3f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages