How to access output from Node.js' request module -


Several tutorials that request and cheerio In these tutorials, they send the output to the console or send the DOM to the file as an example with fs .

  request (link, function, resp, html) {if (return) return console.error (err) var $ = cheerio.load (html), img = $ ('# img_wrapper' ). Data ('src'); Console.log (img);}). Pipe (fs.createWriteStream ('img_link.txt'));   

But what if I want to process the output during script execution? How can I use the output or send it to the call function? I can definitely load img_link.txt and get information from there, but it will be expensive and will not make sense.

You can wrap a request in a function that html

  function (link, callback) {request (link, work (error, im, body) {callback (mistake, body);}); });   

Then assign it to export and use it in any other module.

Comments

Popular posts from this blog

How can I add a seperate action listener to all 14 of my buttons at once that can determine player turn?(java) -

php - Sorting an multidimension array using usort fails -

Simple file compression in C -