Real-Time Web Technologies Guide

Hosted Realtime Services

General Messaging & PubSub

Hydna

Hydna is a hosted backend into which you can send data and have it instantly appear on other devices.

Advertisements

Reliable Delivery Pub/Sub Message Queues with Redis

Redis-title

 

Redis is a high performance key-value datastore that differs from other key-value solutions in the way it handles values. Instead of just storing values as simple strings, it recognizes multiple specific data types such as Lists, Sets, Hashes (maps), Strings or Numbers. Each data type has its own set of features to manipulate the data it contains in an atomic manner, making it an ideal tool for highly distributed system where concurrency is a potential issue.

Combining those features in creative ways allows for novel ways of doing “traditional” things differently. One particular combination has recently allowed us to implement a moderately (read: good enough) reliable message delivery mechanism for multiple consumers consuming messages at their own pace.  Continue reading

This, bind, that in the callback of javascript, node.js

If you want to pass the current object to the callback function in any operation (read file, connect database…)

There are three main ways to deal with this in callbacks:

1. Create a normal variable, as you are currently doing

The most common names for the variable are that and self. I prefer that because in the browser there is a global window property called self that I’d rather not shadow.

function edit(req, res) {
    var that = this,

    db.User.findById('ABCD', function(err, user){
        that.foo(user);
    });
}; Continue reading 

Making HTTP Requests in Node.js

In previous articles, I’ve focused on creating a Node.js server to handle HTTP requests. This article looks at the problem in reverse, by showing you how to make HTTP requests from your Node.js applications. You may be asking yourself why you would want to do that. Two applications come to mind right away –web scraping and proxying. Scrapers are pieces of software which download web pages and programatically extract information from them. Proxy servers act as intermediaries, forwarding client requests to other servers and returning the responses.

The Request Module

The simplest way to create HTTP requests in Node.js is by using the request module. Written by Mikeal Rogersrequest allows you to make all types of HTTP requests, including GETPOSTPUT, and DELETE. Its flexibility makes the request module ideal for interacting with RESTful APIs. You can install request using the following npm command. Continue reading

Node.js – What is “this”?

Most people that learn JavaScript are coming from a background in another language. This brings with it a view of how the world works that may be different from how it really works in JavaScript. For this and other reasons, JavaScript is often misunderstood. It’s not entirely our fault, the language was designed to work like one thing (scheme-like), but look like another (c-like). This article will describe lexical scope and the “this” variable and how to control them rather than be controlled by them when in coding JavaScript. Continue reading

Under the hood of Socket.IO namespaces

I am working on a very simple game using NodeJS and Socket.IO. I decided to separate my game and chat communication into two namespaces in Socket.IO to make the logic a bit easier to follow. One problem I encountered was that I wasn’t sure how to broadcast to all connected clients in a specific namespace. If you’re not dealing with namespaces, it’s simple: Continue reading

Getting started with node.js and socket.io

Getting started with node.js and socket.io

I’ve been thinking of creating an HTML5 game and looking at the technology I’d need for it. I needed something to handle real-time communication for the backend and it looked like one of the leading contenders was node.js along with socket.io. I started searching for a tutorial to get started, and while I found a few, many were out of date. So I’m taking what I learned and describing it here.We’re going to build a simple site that reports on the number of clients connected. As clients come and go the number of connected clients will increase or decrease automatically. Continue reading