Publish and Subscribe for Node.JS SDK

Download pubnub eBook

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
    }); 
}

Stats

Contributors: 3
2016-07-29
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook