Looks like you are using HackerRank
If you see at the dropdown, you will see that you are using some version of node
as language.
Well, if you go over the Node documentation you will find a native http
(or https
) method to perform requests:
here the documentation for Node v12 (refer to the one hackerrank is using)
https://nodejs.org/dist/latest-v12.x/docs/api/http.html#http_http_get_url_options_callback
tldr:
http in node with NO error handling:
var http = require("http");
http.get('URL', (res) => {
res.setEncoding("utf8");
let body = "";
res.on("data", data => {
body += data;
});
res.on("end", () => {
body = JSON.parse(body);
console.log(body);
});
});