I'm new to javascript and I find this very surprising as I come from python. All modules I've seen so far cover how their functions will work with console.log(output), but modifying the code to return output
won't work at all as it's returning undefined
. As an example, I'm including two such modules:
https://www.npmjs.com/package/cryptocompare
https://www.npmjs.com/package/node-coinmarketcap
As you can see, cryptocompare gives an example on the usage of their function:
cc.priceMulti('BTC', 'USD')
.then(prices => {
console.log(prices)
// -> { BTC: { USD: 1114.63 } }
})
Changing this code to:
cc.priceMulti('BTC', 'USD')
.then(prices => prices )
will now return undefined, whereas it was logging correct object before. I tried googling and searching for documentations for this, but I don't know a correct query
that would describe this question. I found tons of modules that just support console.logging, but never indicate how do we make the objects tangible. I wonder why is this happening, because after all the reason we all want to use modules is to use their returned objects in one way or another, and not only print them right?
This is what returns undefined:
const cc = require('cryptocompare')
function fetchPrices(){
cc.priceMulti(['BTC', 'ETH', 'LTC', 'DASH'], ['USD'])
.then(prices => prices)
}
console.log(fetchPrices())