const https = require('https');

/**
 * Request helper. No need to use external package for this.
 * Used in node environment. Please don't use in front-end.
 */
const request = options => {
  return new Promise((resolve, reject) => {
    const req = https.request(options, res => {
      let data = [];
      res.on('data', chunk => {
        data += chunk;
      });
      res.on('end', () => {
        resolve(data);
      });
    });

    req.on('error', err => {
      reject(err);
    });

    req.end();
  }).catch(error => {
    console.log(error);
  });
};

module.exports = request;
