Created
January 23, 2019 02:52
-
-
Save praveen-me/042b80250fbed2ca882735e619f41b04 to your computer and use it in GitHub Desktop.
Fetch asynchronous multiple requests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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