BLOCKSQuick Start Summary

In this Quick Start, we will lead you through a step-by-step guide of how to create and deploy a block in the PubNub Data Stream Network.

Just like other features of the Data Stream Network, PubNub BLOCKS must be enabled on a per Keyset basis.

To enable a Keyset:

  1. Go to the Keyset Configuration via the admin portal.
  2. Scroll down to the PubNub feature section and turn on the BLOCKS toggle.

Voila! You can now create BLOCKS for this Keyset.

Now that your Keyset is enabled for PubNub BLOCKS, let's create a block.

  1. Go to the BLOCKS page by clicking the BLOCKS icon in side bar.
  2. Create a block by entering a name and a description in the square tile.

The block's name and description can always be changed.

Create a Block


The block name must be unique for all BLOCKS under a given Keyset.

A block is used as a container to group related EH(s) together. Since we just created this block, it contains no Event Handlers (EH), so we'll create it now.

To create an Event Handler(EH), click on the New Event Handler icon.

Create and Configure Event Handlers

In the pop up window, configure your EH by:

  1. Entering a name.
  2. Entering an Event Handler Type.
  3. Entering one or more channels.

An EH must have an Event Handler Type (ET) defined for it.

Currently three types of Event Handlers are supported:

  • Before Publish or Fire
  • After Publish or Fire
  • After Presence

For more information on Event Handler Types, please see Event Handler Types

An EH can be triggered by messages sent to one or several channels, and must always have at least one channel defined for it.

For an EH to execute against messages sent to a single channel, enter the channel name in the channel field.

if you adopt a naming convention with 2 levels of depth when specifying your channels, you can subscribe to channels by using wildcards.

For example, if you have several channels named foo.bar1, foo.bar2, foo.bar3, …, foo.barN, your Event Handler can subscribe to all these channels by entering in the channel field: foo.*

For more information on wildcard subscribing see

And now the fun part starts. Coding! At this step, you can write your code logic in standard JavaScript. This code will be executed against every message received against the predefined channels.

Code your Event Handlers

Now that you have coded all the EH(s) in your block, you have to provision the servers, scale out the network, and deploy your block.

This is all done simply by clicking the Run button.