Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var http = require('http');
  2. var async = require('async');
  3. var fs = require('fs');
  4.  
  5. async.parallel([
  6.     function(callback){
  7.         var options = {
  8.           host: 'onet.pl',
  9.           port: 80,
  10.           path: '/',
  11.           method: 'GET'
  12.         };
  13.         var req = http.request(options, function(res) {
  14.           console.log('STATUS: ' + res.statusCode);
  15.           console.log('HEADERS: ' + JSON.stringify(res.headers));
  16.           res.setEncoding('utf8');
  17.           res.on('data', function (chunk) {
  18.             console.log('BODY: ' + chunk);         
  19.             fs.writeFile('/tmp/onet.txt', chunk, function (err) {
  20.               if (err) throw err;
  21.               console.log('It\'s saved!');
  22.             });
  23.           });
  24.         });
  25.         req.end();
  26.         callback(null,"onet"); 
  27.      },
  28.     function(callback){
  29.         var options = {
  30.           host: 'google.com',
  31.           port: 80,
  32.           path: '/',
  33.           method: 'GET'
  34.         };
  35.         var req = http.request(options, function(res) {
  36.           console.log('STATUS: ' + res.statusCode);
  37.           console.log('HEADERS: ' + JSON.stringify(res.headers));
  38.           res.setEncoding('utf8');
  39.           res.on('data', function (chunk) {
  40.             console.log('BODY: ' + chunk);
  41.             fs.writeFile('/tmp/google.txt', chunk, function (err) {
  42.               if (err) throw err;
  43.               console.log('It\'s saved!');
  44.             });
  45.           });
  46.         });
  47.         req.end();
  48.         callback(null,"google");
  49.     }
  50. ], function(error, arg) { console.log("ok");console.log(arg); });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement