# basic node.js controller action with get request

var fs = require('fs');
const requestHandler = require('../validations/requestHandler');

exports.index = (req, res) => {
try {
requestHandler(req);
var options = {
'method': 'GET',
'hostname': 'products.torrent.com',
'path': '/torrent/product',
'accept': 'text/plain',
'WebServiceToken': '3A4SnowWqg+Xf0TgMoTEZ12B4AJ1='
},
'maxRedirects': 20
};
var body = null;
var request = https.request(options, function (result) {
var chunks = [];

result.on("data", function (chunk) {
chunks.push(chunk);
});

result.on("end", function (chunk) {
body = Buffer.concat(chunks);
console.log(body.toString());
});

result.on("error", function (error) {
console.error(error);
});
});

request.end();
res.json(body);

} catch(err) {
next(err);
}
}


I don't use ES6, so don't point it out, I don't want to set it up just yet, but I am wondering if we can cut down on some code, because this doesn't seem clean at all. I am not sure if there's a better library for handling requests, because I feel this is way too wordy.

• Just FYI: You don't need to "setup" ES6. Node supports most of it out of the box. You can just use it. See node.green Sep 6 '21 at 16:14