Especially for npm I can recommend you the bitcoin plugin which does the TCP communication handling for you:
https://www.npmjs.com/package/bitcoinIf you want to work with promises (resolve, reject) instead of classical callbacks (which I definitely can highly recommend if you want to avoid ugly code), then this plugin should be very helpful:
https://www.npmjs.com/package/bitcoin-promise(It's also what we use at foxmixer.com to generate the addresses out of the bitcoin client).