-1

My problem is that I need in the key_client variable is loaded variable md5 obtained through a module called nodejs get-mac.

The way I'm working it can not get it work.

Always runs before key_client to get mac.

//Get Mac Machine for request
var md5;
node.mac.getMac(function(err, mac){
  var hash = node.crypt.createHash('md5').setEncoding('hex');
  hash.write(mac);
  hash.end();
  md5 = hash.read();
});

//Define host and set keys
var host = 'https://service.herokuapp.com/'
var namespace = 'api/v1'
var api = host + namespace
var key_server = '432565454'
var key_client = md5;
console.log(key_client);
user3058963
  • 105
  • 1
  • 2
  • 8

1 Answers1

0

Try:

//Get Mac Machine for request
var md5;
node.mac.getMac(function(err, mac){
    var hash = node.crypt.createHash('md5').setEncoding('hex');
    hash.write(mac);
    hash.end();
    md5 = hash.read();
    someFunction();
});

function someFunction() {
    //Define host and set keys
    var host = 'https://service.herokuapp.com/'
    var namespace = 'api/v1'
    var api = host + namespace
    var key_server = '432565454'
    var key_client = md5;
    console.log(key_client);
}
jcubic
  • 61,973
  • 54
  • 229
  • 402