Just getting the hang of Sails.js, so any help is appreciated.
I've used an XML service and successfully converted it to JSON using xml2js
var req = https.request(options, function(res) {
var xml = '';
res.on('data', function(chunk) {
xml += chunk;
});
res.on('end', function () {
var result = parseString(xml, function (err, result) {
console.log(JSON.stringify(result)); // Position 1
});
return result;
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.write(data);
var result = req.end();
console.log('Result: ' + JSON.stringify(result)); // Position 2
res.view({ message : 'hello', result : result });
The view is loading fine, and <%= message %>
displays hello
. Good.
Console.log at Position 1 shows the stringified JSON object - Great.
However, Console.log at Position 2 returns Result: true
- Not ideal.
I'm looking for a way to pass that JSON data to my view for further processing. Any suggestions?