Skip to content

Instantly share code, notes, and snippets.

@reggi
Created July 17, 2018 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reggi/c5fea9cb169e0b9e98bb33f5a4223be1 to your computer and use it in GitHub Desktop.
Save reggi/c5fea9cb169e0b9e98bb33f5a4223be1 to your computer and use it in GitHub Desktop.
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