How to get the number of confirmation for Ethereum transaction?

I am developing Ethereum wallet and I'm having one problem. I can get the transaction that was sent to someone's address. At the moment, I want to get the number of confirmation and check it in real time. If I can get the number of confirmation, it is no problem for checking in real time. I am developing in Ubuntu16.14, geth and using web3.js

In Ethereum stack exchange, I found an article on Ethereum exchange but it is not working even if it is checked with green color.

I am not sure how can I get the confirmations. Are there any clear answer?