Good afternoon I have a page called index.js in the route folder of nodejs express.
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 treats the asynchronous code causing the variable to not 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();