Thursday, 8 June 2017

NodeJs get JSON for each url request

Hello i created an JSON downloader with nodeJS if use one url this works fine , the problem begins if i try create several JSON files from an url array, the JSON name should be equal to used url any suggestions? Thanks

im using 2 npm modules

var request = require("request");

var fs = require('fs');

var url =[
    "http://ip.jsontest.com/",
    "http://ip.jsontest.com/",
    "http://ip.jsontest.com/"
]
request({
    url: url,
    json: true
}, function (error, response, body) {
    if (!error && response.statusCode === 200) {
        fs.writeFile("de.json", JSON.stringify(response), function(err){
            if(err){console.log(err);} else {console.log("create"  + url + 'JSON ');}
        });
    }
})



via Alex

No comments:

Post a Comment