PubNub Hello World Publish and Subscribe for Node.JS SDK

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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


Got any PubNub Question?