我正在尝试运行以下节点。js代码通过命令提示符。但是,代码不会执行(命令提示符上没有显示任何错误)。
我已经安装了必要的
pubnub
包使用(
npm install pubnub
)同样如此。但是,问题依然存在。
我错过什么了吗?代码链接在这里
https://www.pubnub.com/docs/nodejs-javascript/pubnub-javascript-sdk#initializing-the-client
var PubNub = require('pubnub')
function publish() {
pubnub = new PubNub({
publishKey : 'demo',
subscribeKey : 'demo'
})
function publishSampleMessage() {
console.log("Since we're publishing on subscribe connectEvent, we're sure we'll receive the following publish.");
var publishConfig = {
channel : "hello_world",
message : "Hello from PubNub Docs!"
}
pubnub.publish(publishConfig, function(status, response) {
console.log(status, response);
})
}
pubnub.addListener({
status: function(statusEvent) {
if (statusEvent.category === "PNConnectedCategory") {
publishSampleMessage();
}
},
message: function(message) {
console.log("New Message!!", message);
},
presence: function(presenceEvent) {
}
})
console.log("Subscribing..");
pubnub.subscribe({
channels: ['hello_world']
});
};