Ram
Ram

Reputation: 5

Async to sync in nodejs

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) })

Upvotes: 0

Views: 1119

Answers (1)

Nikita Namestnikov
Nikita Namestnikov

Reputation: 344

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;});

Upvotes: 1

Related Questions