Skip to content

Instantly share code, notes, and snippets.

@praveen-me
Created January 23, 2019 02:52
Show Gist options
  • Save praveen-me/042b80250fbed2ca882735e619f41b04 to your computer and use it in GitHub Desktop.
Save praveen-me/042b80250fbed2ca882735e619f41b04 to your computer and use it in GitHub Desktop.
Fetch asynchronous multiple requests.
var fs = require('fs');
var axios = require('axios');
var async = require('async');
const Bank = require('./models/Bank');
var codes;
var counter = 0;
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
module.exports = () => {
fs.readFile('./server/IFSC-list.txt', (err, data) => {
if (err) throw err;
codes = data.toString().split("\n");
async.eachSeries(codes, (ifsc, callback) => {
console.log(ifsc, 'ON');
axios.get(`https://ifsc.razorpay.com/${ifsc}`)
.then(function (response) {
const {IFSC, BANK, CITY} = response.data;
var newBank = new Bank({
IFSC,
BANK,
CITY
});
newBank.save();
console.log('saved', ++counter);
callback();
})
.catch(function (error) {
console.log(error);
});
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment