diff --git a/modules/requests.js b/modules/requests.js new file mode 100644 index 0000000..b3e72d5 --- /dev/null +++ b/modules/requests.js @@ -0,0 +1,31 @@ +const http = require("http"); +const https = require("https"); +/** + * @param {String} path + */ +module.exports = (path) => { + return new Promise((res, rej) => { + if(path.startsWith("http://")){ + var handler = http; + } else if(path.startsWith("https://")){ + var handler = https; + } else { + rej(Error("Unsupported protocol")); + } + + handler.get(path, (resp) => { + let data = ''; + + resp.on('data', (chunk) => { + data += chunk; + }); + + resp.on('end', () => { + res(data); + }); + + }).on("error", (err) => { + rej(err); + }); + }); +} \ No newline at end of file