Chapter 9. Chat
The social networking application is off to a good start. It’s possible to share your updates, add and find contacts, and interact with each other all from piecing together some of the useful libraries that are already available for Node.js and Backbone. But if you were to try to use this application in real life, you might find that it feels cold and sterile—it’s certainly a networking site, but it isn’t very social.
It’s time to brighten up the environment by enhancing your features with real-time capabilities. First up: chat!
Online chat presents your users with a means to communicate with one another almost as quickly as if they were having a real conversation. During a chat, the goal of your application should be to deliver messages from one party to the other as quickly as possible, without letting other processes like logging or database retrieval get in the way. A good chat system is really little more than a conduit between two communicators.
Refactoring
On the Node.js side of things, the application is starting to get too large to reasonably handle in a single script, so you’re going to pull all the authentication- and account-related routes out of app.js and move them into their own files. Then you’re going to loop through all of the routes during startup and add them to your application, as shown in Example 9-1.
fs.readdirSync('routes').forEach(function(file){varrouteName=file.substr(0,file.indexOf('.')); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access