Плохо искали
const fetch = require('node-fetch');
let url = "https://www.reddit.com/r/popular.json";
let settings = { method: "Get" };
fetch(url, settings)
.then(res => res.json())
.then((json) => {
// do something with JSON
});
const https = require('https');
let url = "https://www.reddit.com/r/popular.json";
https.get(url,(res) => {
let body = "";
res.on("data", (chunk) => {
body += chunk;
});
res.on("end", () => {
try {
let json = JSON.parse(body);
// do something with JSON
} catch (error) {
console.error(error.message);
};
});
}).on("error", (error) => {
console.error(error.message);
});
const request = require('request');
let url = "https://www.reddit.com/r/popular.json";
let options = {json: true};
request(url, options, (error, res, body) => {
if (error) {
return console.log(error)
};
if (!error && res.statusCode == 200) {
// do something with JSON, using the 'body' variable
};
});