How do I watch a Bitcoin address using NodeJS?

I have bitcoind and NodeJS installed on my VPS.

I want to be notified when a payment is made to a specified bitcoin address.

I suppose something similar to receiving a callback in the Blockchain.info API. "You provide a bitcoin address we generate unique addresses that forwards payments to that address instantly notifying a callback URL." We want to avoid trusting that forwarding process though.

It looks like https://www.npmjs.org/package/bitcoin will help. I'm just not sure on the code specifics from there.

Any code samples on how to use NodeJS to get notified when a bitcoind address receives a payment? Or any other suggestions on other solutions that will do the same thing?

Thanks.

By far the nicest lightweight node.js integration library I've seen is here. Things like Callbacks to check the balance of generated wallets, ways to encrypt and store the private key in localfile, and no need to run a local bitcoin client, just reading through the list made me fork the repo for myself. But I have not yet reviewed over much of the source to know for sure if its trustworthy. Appears to use Bitcore which is a flavor of bitcoinjs-lib I believe.

So basically I would use their own default module displayed as the sample and configure the settings variable with other triggers as specified, in my snipped I modified it for 0 confirmation transactions (micropayments perhaps) AND it also checks every two minutes for confirmations. You can easily see how to change this code to adjust for the number of transactions you want to confirm for. If you like this solution, the homepage for the author which gives more detail about it as well is here:

function(newtransaction) {
var settings = {network: 'live', 
     includeUnconfirmed: 'true',
  checkTransactionEvery: '120000'//in miliseconds}
var acceptBitcoin = require('accept-bitcoin');
var ac = new acceptBitcoin('YOUR_BITCOIN_ADDRESS', settings);
key = ac.generateAddress({alertWhenHasBalance: true});
console.log("Hello buyer! please pay to: " + key.address());
key.on('hasBalance', function(amount){
  console.log("thanks for paying me " + amount); //do stuff
  key.transferBalanceToMyAccount(function(err, d){
    if (d.status === 'success') console.log("Cool, the bitcoins are in my private account!");
  });
});

}