ShelljsExec return \n on parsing

12 views
Skip to first unread message

Woukaine Beyond

unread,
Jun 18, 2017, 1:12:46 AM6/18/17
to nodejs
Hi,

I use this script for get my bitcoin balance : 

app.get('/GET/MY/BITCOIN/BALANCE', function (req, res) {
if( isConnected(req) == true)
{
var child = exec('cd /home/rpcdaemon/wallets/bitcoin-0.14.1/bin; ./bitcoin-cli getbalance ' + req.params.account, {async:true});
child.stdout.on('data', function(data) {
var bitcoin_balance = data;
res.send({"success":true, bitcoin_balance:bitcoin_balance});
});
}
});

the variable "bitcoin_balance" == 0.00000 but return 0.00000\n to my json...

How to fix it ? Thx !

Zlatko

unread,
Jun 19, 2017, 12:24:25 PM6/19/17
to nodejs
You can try a simple parseFloat:

const balance = parseFloat(data);

Just make sure you get an actual number.
Reply all
Reply to author
Forward
0 new messages