Where Should Be Used Node.js
CHAT
The chat application is really the sweet-spot example for Node.js: it’s a lightweight, high traffic, data-intensive (but low processing/computation) application that runs across distributed devices. It’s also a great use-case for learning too, as it’s simple, yet it covers most of the paradigms you’ll ever use in a typical Node.js application.
Let’s try to depict how it works.
In the simplest scenario, we have a single chat room on our website where people come and can exchange messages in one-to-many (actually all) fashion. For instance, say we have three people on the website all connected to our message board.
On the server-side, we have a simple Express.Js application which implements two things:
1) a GET ‘/’ request handler which serves the webpage containing both a message board and a ‘Send’ button to initialize new message input.
2) A web sockets server that listens for new messages emitted by web socket clients.
On the client-side, we have an HTML page with a couple of handlers set up, one for the ‘Send’ button click event, which picks up the input message and sends it down the web socket, and another that listens for new incoming messages on the web sockets client.

No comments:
Post a Comment