I am trying to get my head round node.js…
I am very happy with my LAMP set up as it currently fulfils my requirements. Although I want to add some real-time features into my PHP app. Such as showing all users currently logged into my site and possible chat features.
I don’t want to replace my PHP backend, but I do want scalable real-time solutions.
1. Can I throw node.js into the mix to serve my needs without rebuilding the whole application server-side script?
2. How best could node.js serve my ‘chat’ and ‘currently logged in’ features?
Great to hear your views!
W.
I suggest you use Socket.io along side node.js. Install and download the libs from http://socket.io/. You can run it along side your Apache server no problems.
First create a node server:
Second, run your server from the command line using:
Third, connect to the socket using client side js:
You will have to have include the socket.io lib client side aswell.
Send data from client side to the node server using:
Your server.js should also have functions for processing requests:
There are two main ways to send data from the server to the client:
and