Book Image

Building Scalable Apps with Redis and Node.js

By : Joshua Johanan
Book Image

Building Scalable Apps with Redis and Node.js

By: Joshua Johanan

Overview of this book

Table of Contents (17 chapters)
Building Scalable Apps with Redis and Node.js
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using namespaces or rooms


We have now used both and can see that rooms and namespaces in Socket.IO are really similar. They are both ways of segmenting all the connections into groups. This leads us to the question, when do we use either of them?

Namespaces

JavaScript is a scripted language that executes in essentially one context. If you create a function in a different file (without using any module or closure system), it is created in the global scope. Identically named functions will overwrite each other. If you have used any strongly typed object-oriented language (C#.NET or Java are two examples), you will have seen and used namespaces. Namespaces in those languages allow you to create objects with the same name, but they would be separate as they will live in different namespaces, otherwise known as scopes.

This is the same thought process you should have with Socket.IO namespaces. If you are building a modular Node web application, you will want to namespace out the different modules...