Created
July 17, 2018 17:18
-
-
Save reggi/c5fea9cb169e0b9e98bb33f5a4223be1 to your computer and use it in GitHub Desktop.
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 _ = require('lodash') | |
const bb = require('bluebird') | |
bb.promisifyAll(fs) | |
async function example () { | |
const file = await fs.readFileAsync('./urls.txt','utf8') | |
const urls = file.split('\n') | |
const action = await bb.map(urls, async (url) => { | |
const res = await axios.get(url) | |
const content = JSON.stringify(res.body) | |
const path = _.camelCase(url) | |
const write = await fs.writeFile('./json/' + path, content) | |
return {res, content, path, write} | |
}) | |
return action | |
} | |
example().then(console.log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment