I'm currently in the process of setting up a MEAN app, however I've hit a roadblock when it comes to extracting data from a webservice into my application. While returning a basic variable poses no issue, I am unsure how to retrieve the result from the webservice.
The output from the webservice is visible in the terminal console, but not on the frontend (angular). When attempting to return the 'options' variable, it displays in the frontend console, but the webservice result does not. Instead, I receive
$promise: Object, $resolved: false,
I'm constructing this using MEAN.js
Here is what I have thus far
shop.server.route.js
'use strict';
/**
* Module dependencies.
*/
var shop = require('../../app/controllers/shop.server.controller.js');
module.exports = function(app) {
app.route('/shop')
.get(shop.listProducts);
};
shop.server.controller.js
'use strict';
var http = require('http'),
errorHandler = require('./errors.server.controller');
/**
* List of Products
*/
exports.listProducts = function(req, res) {
var options = {
host: 'http://api.example.com',
path: '/products?param1=1¶m2=2'
};
req = http.get(options, function(res) {
var body = {};
res.on('data', function (chunk) {
body += chunk;
});
res.on('end', function () {
console.log('Got Response' + body );
});
});
req.on('error', function(err) {
console.log( err.message);
res.send('error:' + err.message);
});
};