Skip to content

Instantly share code, notes, and snippets.

@serganus

serganus/app.js

Created Nov 17, 2017
Embed
What would you like to do?
Multiple Requests (Promisified)
var __request = require('./logic.js').__request;
var urls = ["http://www.example.com/firts", "http://www.example.com/second", "http://www.example.com/third"];
__request(urls, 'GET', false);
'use strict';
var request = require('request');
var rp = require('request-promise');
var __request = function(urls, HTTP_method, gzip_Boolean) {
var results = {};
var t = urls.length;
var c = 0;
while (t--) {
rp({
method: HTTP_method,
uri: urls[t],
gzip: gzip_Boolean
}).then(function(body){
results[t] = {
err: false,
data: response
};
console.log(results);
}).catch(function(error){
results[t] = {
err: {
status: true,
name: error.name,
message: error.message
}
};
console.log(results);
});
}
return results;
};
exports.__request = __request;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment