Adam Muller Adam Muller - 1 month ago 8
Node.js Question

console.log in callback instead of a function

I'm using the block.io API, and for each methods, in the examples, they use console.log as callback.

I don't understant how it works, I tried to get it in a function, but i get 'null'.

If I use console.log, it writes null first, then the object.

it tried :

block_io.get_new_address({}, (data) => {
console.log(data)
})


Here is the API : https://block.io/api/simple/nodejs

Someone can explain me how to deal with it ? Thanks

Answer

open the console in your browser, and type typeof console.log you will get "function", it's like any function with parentheses so imagine with block.io:

> block_io.get_new_address({'label': 'shibe1'}, ``function here``);

will be

> block_io.get_new_address({'label': 'shibe1'}, console.log);

and all of this is just an example of how to use it, check this out :

// please use the Dogecoin Testnet API key here
var client = new BlockIo({
  api_key: 'YOURDOGECOINTESTNETAPIKEY',
  version: 2
});

client.get_new_address({label: 'testDest'}, function (error, data) {
  if (error) return console.log("Error occured:", error.message);
  console.log(data);
});

https://github.com/BlockIo/block_io-nodejs/blob/master/examples/basic.js

Comments