Skip to Content
Building Node Applications with MongoDB and Backbone
book

Building Node Applications with MongoDB and Backbone

by Emily Wilson
December 2012
Beginner to intermediate
204 pages
4h 34m
English
O'Reilly Media, Inc.
Content preview from Building Node Applications with MongoDB and Backbone

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.

Example 9-1. Moving routes to their own files
fs.readdirSync('routes').forEach(function(file) {
  var routeName = 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

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Node.js, MongoDB, and AngularJS Web Development

Node.js, MongoDB, and AngularJS Web Development

Brad Dayley

Publisher Resources

ISBN: 9781449337735Errata Page