I'm trying to connect my node.js discord bot to my Rest API. I already look after some help on stackoverflow in this topic:
How to make remote REST call inside Node.js? any CURL?
I'm stuck in the GET part of the function. The data I want is sent to the console but the bot don't receive it, while it receive hardcoded data.
Here is my code:
function execute_testrest(callback) {
var options = {
host : 'localhost',
port : '55978',
path : '/api/values',
method : 'GET'
};
console.info('Options prepared:');
console.info(options);
console.info('Do the GET call');
var reqGet = http.request(options, function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
res.on('data', function(d) {
console.info('GET result:\n');
process.stdout.write(d);
callback(d);
console.info('\n\nCall Completed');
});
});
reqGet.end();
reqGet.on('error', function(e) {
console.error(e);
})
}
The data is well displayed in the console with the process.stdout.write(d); line, but doesn't appear in the bot response. I can get a hardcoded response with callback("response");, but not with callback(d)
It would be great if someone could help me a bit. thanks in advance
EDIT: Here are both the application log and the result on Discord