You should use Socket.io to have make your Real-Time application.
I just founded a nice blog article which speaks about real time edition, see here. It's also providing a link to the github project and to an open source online editor project. Take a look and try to understand how they do stuff like this, good luck !