Skip to content

Instantly share code, notes, and snippets.

@dtornow
Last active August 29, 2015 14:06
Show Gist options
  • Save dtornow/823893b3320001b7f56c to your computer and use it in GitHub Desktop.
Save dtornow/823893b3320001b7f56c to your computer and use it in GitHub Desktop.
PubNub
var npm = require("npm"),
querystring = require("querystring");
if(process.env.CHANNEL && process.env.PUBLISH_KEY && process.env.SUBSCRIBE_KEY) {
npm.load({}, function (err) {
npm.commands.install(["pubnub"], function (err) {
var header, body;
try {
header = querystring.parse(process.env.HTTP_HEADER);
} catch(ex){
header = process.env.HTTP_HEADER;
}
try {
body = JSON.parse(process.env.HTTP_BODY);
} catch(ex){
body = process.env.HTTP_BODY;
}
var pubnub = require("pubnub").init({
publish_key: process.env.PUBLISH_KEY,
subscribe_key: process.env.SUBSCRIBE_KEY
});
pubnub.publish({
channel : process.env.CHANNEL,
message : {header: header, body: body},
callback : function(e) { console.log( "SUCCESS", e ); process.exit(0); },
error : function(e) { console.log( "FAILURE", e ); process.exit(500); }
});
});
});
} else {
process.exit(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment