I am developing an application on MEAN JS. I am new on MEAN JS.
I want to access an external API to get a json respone as following -
{"id":"7gd6ud7ud5r0c","name":"jack","zip":"94109","gender":"Male"}
I have this reference here (https://nodejs.org/api/https.html)..
But I dont know how to use the http/https request inside a client controller.
Here is my express.js
'use strict';
/**
* Module dependencies.
*/
var fs = require('fs'),
http = require('http'), // required already
https = require('https'), // required already
express = require('express'),
morgan = require('morgan'),
bodyParser = require('body-parser'),
.....
.....
.....
Here is my invite.client.controller.js
'use strict';
angular.module('core').controller('InviteController', ['$scope',
'Authentication', '$http',
function($scope, Authentication, $http) {
// This provides Authentication context.
$scope.authentication = Authentication;
$scope.getMembersFromAPI = function(){
***************************************
// this block shows error ReferenceError: require is not defined
var http = require('http'),
https = require('https');
***************************************
var options = {
hostname: 'https://api.somedemodp.com/v5/td?api_key=ec96c9afcbb6bbb8f5a687bd7&email=vlad@rapleafdemo.com',
path: '/',
method: 'GET'
};
var req = https.request(options, function(res) {
console.log('statusCode: ', res.statusCode);
console.log('headers: ', res.headers);
res.on('data', function(d) {
process.stdout.write(d);
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
};
}
]);