Reputation: 2090
I have a json content on a particular URL. I want to download that json content to a file say test.json.
Upvotes: 1
Views: 1700
Reputation: 5253
You can use the node-fetch
module:
var fetch = require('node-fetch');
fetch('https://example.com/file.json')
.then(function(response) {
var destination = fs.createWriteStream('./destination-file.json');
response.body.pipe(destination);
});
Upvotes: 1
Reputation: 2090
Found the answer myself,
I used the "packages" request and "fs"
var request = require("request");
var fs = require("fs");
request
.get(theURLWithJson)
.on('error', function(err) {
console.log('err', err);
})
.pipe(fs.createWriteStream(fullFilePathWithFileName));
Upvotes: 0