Hello World

Other topics

Remarks:

<init> (i.e. require ("pubnub"))

Initialize an instance of PubNub to invoke operations.

ParameterDetails
publish_keyString - your publish key from your PubNub Admin Dashboard account
subscribe_keyString - your publish key from your PubNub Admin Dashboard account

subscribe

Subscribe to a channel(s) and provide a means to receive messages published to the channel(s).

ParameterDetails
channelString - channel name or comma-delimited list of channel names
messagefunction - the callback function that will receive messages published on the subscribe channels
connectfunction - the callback function that will be called when the subscription to the channels is successful

publish

Publish a message to a channel which will be received by subscribers on that channel.

ParameterDetails
channelString - channel name on which to send the message
messageString - The message to publish on the channel. JSON format is recommended (do not stringify; use the JSON object)

Publish and Subscribe for Node.JS SDK

Publish and Subscribe for Node.JS

Install PubNub NPM Package.

npm install [email protected]

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

Contributors

Topic Id: 329

Example Ids: 1153

This site is not affiliated with any of the contributors.