我有一种情况,我需要从我的控制器文件夹中为服务文件夹中的服务功能提供服务,一旦我收到输出,我需要将其传递回 UI。
//controller
var service = require('service');
api.get('/users', function(request, response) {
var name = request.query['name'];
var responseFromService = service.someAPI(name);
response.send(responseFromService).status(200);
});
//Service
exports.callTwitterAPI = function(twitterHandle,callback){
var responseFromTwitterService;
console.log("Calling Twitter API.." + twitterHandle);
someAPI.get('users/show', {screen_name: twitterHandle}, function (err, data, res) {
if (err) {
//loggerError.error('No connection to twitter :', Date.now());
responseFromTwitterService = JSON.stringify(err) + "Unable to connect twitter";
} else if (data.errors) {
responseFromTwitterService ="User Not Found!!"
// loggerInfo.info('No Twitter handle found for :', twitterHandle);
} else {
console.log("here..");
responseFromTwitterService = data;
}
console.log('response : '+ responseFromTwitterService);
return (null,responseFromTwitterService);
});
}
现在,我需要执行
response.send(responseFromService).status(200);
在我的服务返回响应之前,我需要使其同步。
提前致谢 :)