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

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -