PubNub Publish and Subscribe for Node.JS SDK

Download PubNub for free

Example

Publish and Subscribe for Node.JS

Install PubNub NPM Package.

npm install pubnub@3.15.2

Example Publish Subscribe with Node.JS

var channel = "hello_world";
var pubnub = require("pubnub")({
    publish_key   : "your_pub_key"
,   subscribe_key : "your_sub_key"
});

pubnub.subscribe({
    channel : channel
,   message : receive  // print message
,   connect : send     // send message after subscribe connected
});

function receive(message) { console.log(message) }

function send(message) { 
    pubnub.publish({ 
        channel : channel 
    ,   message : message
    }); 
}
Message Filtering