angularjs - Unable to get a JSON response from my express router using node-Fetch module -
so i'm making post request express search router i'm using node-fetch module call remote api:
var fetch = require('node-fetch'); router.route('/search') //performs job search .post(function(req, res){ var area = req.body.area; fetch('https://api.indeed.com/ads/apisearch?publisher=*********&l=' + area) .then(function(res) { return res.json(); }).then(function(json) { console.log(json); }); })
i'm using angular 1 on client side call router , parse returned json:
$scope.search = function(){ $http.post('/api/search', $scope.newsearch).success(function(data){ if(data.state == 'success'){ //perform json parsing here } else{ $scope.error_message = data.message; } }); }
i'm starting out mean stack , have vague idea of how promises work. issue angular search function not getting json string want return remote api call. rather data parameter getting set page html. breakpoints i've set in .then() clauses hit , json returned. question how can use anguular json values when returned????
can try this?
router.route('/search') //performs job search .post(function(req, res){ var area = req.body.area; fetch('https://api.indeed.com/ads/apisearch?publisher=*********&l=' + area) .then(function(result) { res.json(result); //or possibly res.send(result), depending on indeed responds }) })
Comments
Post a Comment