Node.jsNode.jsPhoneGapReact V4WebJavaScriptNode.JS V4 Misc API Reference for Realtime Apps

Go to Mobile Push


End all open requests and close PubNub instance.
pubnub.stop();
This function allow to decrypt the data.
To decrypt the data you can use the following method(s) in NodeJS V4 SDK.
  1. ParameterTypeRequiredDescription
    dataStringYesThe data to decrypt.
    customCipherKeyStringOptionalIf it's not provided, the cipher key from config will be used.
var decrypted = pubnub.decrypt(encrypted, 'myCipherKey'); // Pass the encrypted data as the first parameter in decrypt Method
It returns the decrypted data as an object.
This function allow to encrypt the data.
To encrypt the data you can use the following method(s) in NodeJS V4 SDK.
  1. ParameterTypeRequiredDescription
    dataStringYesThe data to encrypt.
    customCipherKeyStringOptionalIf it's not provided, the cipher key from config will be used.
var sCypher = "testCypher";
var msgContent = "This is the data I wish to encryt.";
console.log('msgContent: ' + msgContent);

// Encrypt with pubnub
var encryptedMessage = pubnub.encrypt(JSON.stringify(msgContent),sCypher);
console.log('encryptedMessage PN: ' + encryptedMessage);
It returns the encrypted data as string.
Call the reconnect method to force the SDK to try and reach out PubNub.
To reconnect the data you can use the following method(s) in NodeJS V4 SDK.
  1. This method doesn't take any arguments.

pubnub.reconnect();
Call setProxy() to instruct the SDK to assign or reassign a proxy configuration in run time.
To setProxy the data you can use the following method(s) in NodeJS V4 SDK.
  1. ParameterTypeRequiredDefaultsDescription
    hostnameStringYesSpecifies the IP address the or URI to use.
    portNumberYesSpecifies the port which the proxy will be listened.
    protocolStringOptionalhttpSupported Protocols are http, https, socks5, socks4 and pac.
pubnub.setProxy({
	hostname: 'YOUR HOSTNAME HERE',
  	port: 8080,
	protocol: 'YOUR PROTOCOL HERE'
});
  1. pubnub.setProxy(null);
This function will return a 17 digit precision Unix epoch.
 
Timetoken
The timetoken is constructed using the following algorithm:
timetoken = (Unix epoch time in seconds) * 10000000
Example of creating a timetoken for a specific time & date
08/19/2013 @ 9:20pm in UTC = 1376961606
timetoken = 1376961606 * 10000000
timetoken = 13769616060000000
To fetch Time you can use the following method(s) in NodeJS V4 SDK
  1. ParameterTypeRequiredDescription
    callback Function YesCallback is called after a successful return.
// assuming an initialized PubNub instance already exists
pubnub.time(function(status, response) {
	if (status.error) {
		// handle error if something went wrong based on the status object
	} else {
		console.log(response.timetoken);
	}
})
//Example of status
{
    error: false,
    operation: 'PNTimeOperation',
    statusCode: 200
}

//Example of response
{
    timetoken: 15031768233407550
}
  1. pubnub.time().then((timetoken) => {
        console.log(timetoken);
    }).catch((error) => {
        console.log(error)
    });