Tuesday 23 May 2017

Download a json file from a link using Node js

I need to write an application with Node JS which given a link to a json file e.g http://data.phishtank.com/data/online-valid.json (The link doesn't open the file it opens a download), the program simply downloads the object and then prints it out. How can this be achieved? This is what I have so far and it doesn't seem to be working:

var checkIfPhishing = function(urlToPrint){
    var http = require('http');
    var fs = require('fs');

    var file = fs.createWriteStream("SiteObject.json");
    var request = http.get(urlToPrint, function(response) {
    response.pipe(file);});

    var siteObj= fs.readFileSync("SiteObject.json");

    console.log(siteObj);

};

Thank you!



via Nivolas

No comments:

Post a Comment