Nameless Package Manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


1.3.3 • Public • Published



ChatUp is a highly performant, scalable and extensible chat platform based on websockets.

It uses NodeJS, Redis and Nginx with the PushStream Module.

ChatUp is:

  • SCALABLE on multiple servers
  • SECURE with JSON Web Token Authentication to integrate in an existing system
  • EXTENSIBLE via server-side and client-side plugins
  • MODULARIZED in multiple micro-services
  • USED AT LARGE SCALE and created for Streamup

Table of Contents generated with DocToc

Test it with Docker

ChatUp is available on Docker. You can use this image to test it quickly or to deploy it easily in production.

To do so, execute those three commands:

docker run --name chatup-redis -d redis # Create a redis server 
docker run --link chatup-redis:redis -e CHATUP_REDISHOST=redis --name chatup-dispatcher -d geekuillaume/chatup ./entrypoint.js dispatcher # Start the dispatcher service in charge of the load-balacing 
docker run --link chatup-redis:redis -e CHATUP_REDISHOST=redis --name chatup-worker -d geekuillaume/chatup ./entrypoint.js worker --use-container-ip # Start the worker service in charge of all the communication 

You can then get the dispatcher IP with docker inspect --format '{{ .NetworkSettings.IPAddress }}' chatup-dispatcher and use the example client page indicating this IP to test it.

You can spawn multiple workers they will be load-balanced without having to do anything else. If you want to add multiple dispatchers, you need to put a load-balancer in front of them.


By default, the chat uses example key for the JWT verfication. To test it use the awesome website with the RS256 algorithm and the public and private example keys. In production, create a new Docker image from geekuillaue/chatup and include your key.

Here is a basic JWT and it's payload:

  "name": "Test 1",
  "_public": {
    "name": "Test 1"


  • Blacklist: blocks messages containing specific strings, administrable via an API on the dispatchers
  • Slack: sends a message to a Slack channel when a message containing a specific string is sent
  • Rate Limiter: limits the number of messages a user can send to avoid spamming

How to Install

On Ubuntu (tested on 14.04):

curl '' | bash

You can look at the script but basically, it installs Git, NodeJS, Nginx, clone this repo and install its NodeJS dependancies.

For other plateforms, you can port the script very easily.

How to use

There is three type of installations, each of them can be used simultaneously on the same machine of scaled to N machines.

For fault-tolerancy, you need to have at least 2 of each.


The dispatcher handles the initial request of the client and redirects him to the best ChatWorker. It's also used for statistics.

To start a dispatcher, simply start the corresponding example script with:

node examples/dispatcher/index.js

You then need to load-balance the clients requests to all the dispatchers and point the client to the correct URL.

Chat Worker

The Chat Worker is responsible for all the messages in the chat rooms. It's composed of two elements, the NodeJS service that receives the messages from the clients and Redis, and Nginx (with PushStream) that broadcast these messages to the connected clients.

You need to have these two elements running on the same machine.

To start the ChatWorker Nginx service:

node examples/chatWorker/index.js

To start Nginx:

sudo /usr/local/nginx/sbin/nginx -c $PWD/examples/chatWorker/nginx.conf

(You need to indicate the absolute path of the nginx configuration file)


Redis is used for messaging between all the other components. You simply have to install it and point the dispatchers and ChatWorkers to it.

Client lib

The client lib is separated in two classes: ChatUpProtocol and ChatUp. The first handles all the messages and fault-tolerancy and the second is an integration with HTML and CSS.

The client lib is packaged with all its dependancies thanks to Browserify and exposes these two classes to the window.ChatUp object (so use window.ChatUp.ChatUpProtocol or window.ChatUp.ChatUp).

You can also see the example page to test your installation.

You can modify use the ChatUp class as a starting point for your implementation.

How does it works

When the client FOO want to join the channel BAR:

  • the client sends a request to the dispatchers asking to join channel BAR
  • the dispatchers replies with the hostname of an available worker
  • the client initiates the SUBSCRIBER websocket with the worker and receives the last X messages

If the client is connected and want to send message:

  • the client initiates the PUBLISHER websocket with the worker and sends its JWT
  • the worker verifies it and if correct accept the connection
  • the client can send a message to the PUBLISHER websocket and they will be broadcasted to every worker and every clients in the specific channel


How to use SSL

SSL is supported in ChatUp but you need to attach a valid domain to your ChatWorkers as certificates cannot be attached to an IP.

To activate SSL, see the corresponding examples files.

How to transmit user information

User information are stored inside the JSON Web Token. This token must be signed by you authentication server and passed to the client.

Inside this token, you must include a _public object that will be broadcast to all the rooms clients on each message. It will also be available in the dispatcher stats.

How to ban users

You can ban a user on a channel by making a POST request to one of the dispatcher on the endpoint /ban.

The body of this POST request needs to be a JSON Web Token containing an array of the users to ban, channel on which to ban them and an optionnal ban expire (in seconds). Here an example of a JSON web token content:

  "name": "test1",
  "channel": "TestRoom",
  "expire": 30
}, {
  "name": "test2",
  "channel": "TestRoom2"

Using the example Public/Private key pair with this example makes the following JWT:


The name is matched against the name field of the _public sent in the client JSON web token.

How to get messages history of a room

You can configure the Chat Worker to keep in cache (on Redis) the last N messages (look at the example file for the Chat Worker). These messages are available on an API endpoint from the Dispatcher. You can access these messages by requesting the /messages/:channelName route.

Remarque: These messages are only available from the API endpoints, it's different from the messages in cache served when a new user connects. Thoses messages are stored directly in Nginx and are automatically fetched on connection start by the Client Lib.

How to use additional channels

You can configure a client to listen on additional channels to be able to send him specific notifications. To do that, just add the additionalChannels property in the client configuration (look at the example for a concrete use).

These channels can be used to send a message to a specific user or to broadcast a message to all your users.

How to post a message from the API endpoint

You can use the POST /post API endpoint to send multiple messages to specific channels. This request body must be a JWT containing something like this:

  "channel": "notifications",
  "msg": "This is a test",
  "user": {
    "name": "Server"
}, {
  "channel": "notifications2",
  "msg": "This is a second test",
  "user": {
    "name": "Server 2"

The message will be broadcasted to all Chat Workers and then to all clients that are subscribed to the channel.

You can also replace the msg field by the ev field in a message. This message will then be caught by the onEv handler in the client lib. When you use the ev field, you can also include the data field who can be anything and will be passed to each client.



See the LICENSE file for more information.


ChatUp has been developed for Streamup by myself, Guillaume Besson. After some talks, we decided to publish it freely for other to use.

It's currently used on Streamup under high load and going strong.




npm i chatup

Downloadsweekly downloads









last publish


  • avatar