I am using request module to return values . {code}
var token;
const request = require('request');
const authKey='Bearer <APPKEY>'
const ContentType='application/x-www-form-urlencoded' ;
var postData={
'grant_type':'client_credentials'
};
const options = {
url: '<m/c detils>',
method: 'POST',
headers: {
'Content-Type': ContentType,
'Authorization':authKey
},
body:require('querystring').stringify(postData)
};
module.exports.getAccessToken=request(options, function(errror, response, body){
console.info("Token is caling");
// body...
console.info("inside request module----------------------",JSON.parse(body));
console.info("response details---------------------",response);
token= JSON.parse(body).access_token;
console.info("token1---------------------",token);
return token;
})
)
{code}
Here I am able to return value for token ,but same thing if I want to use in another file for eg ::
var token = authtoken.getAccessToken;
I am getting value as undefined ,I have did
var authtoken=require('./utils/Utils.js');
Please help me out here