0
good afternoon I own a page called index.js in the route folder of the express nodejs.
when the pendingAprovals page is called I would like the index to call a webservice to send a JSON to the pendingAprovals, but the Node handles the asynchronous code causing the variable not to be populated.
below the code I have:
index js.
var options = {
host: 'localHost',
port: 7001,
path: 'meuWebService/meuMetodo',
mothod: 'GET',
header: { 'Content-Type': 'application/json; charset=utf-8' }
};
var list =
http.request(options, function(res) {
var body = "";
res.setEncoding('utf-8');
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
list = JSON.parse(body);
console.log(JSON.stringify(body));
});
});
list.end();
mothod: 'GET',
Is this a copy-to error or is that what you have in the options, really? try to exchange formethod: 'GET'
– MoshMage
adjusted but still does not work synchronously
– user2913044