0

I am using this library getmac to get the MAC address of the server on which the nodejs is running. Basically the API to get the MAC address is async but I want to use it as sync call. Is this possible without using any libraries like sync, deasync etc?

//async API require('getmac').getMac(function(err,macAddress){ if (err) throw err console.log(macAddress) })

Ram
  • 5
  • 5
  • 1
    Possible duplicate of [How to wrap async function calls into a sync function in Node.js or Javascript?](http://stackoverflow.com/questions/21819858/how-to-wrap-async-function-calls-into-a-sync-function-in-node-js-or-javascript) – F. Kauder Aug 08 '16 at 14:19
  • you can use callback to convert the async to sync or Use async module – Lav Vishwakarma Aug 08 '16 at 14:26

1 Answers1

1

You can use this package

var done = false;
require('getmac').getMac(function(err,macAddress) { 
    if (err) throw err 
    console.log(macAddress)
    done = true;
});
require('deasync').loopWhile(function(){return !done;});
  • Basically I wanted to avoid using a new library because that would need re-issuing the whole environment but anyway I can live with this one. Thanks. – Ram Aug 09 '16 at 11:07