So I have written a couple of blogs about Push Notifications with a bit of Java (see here as the post that pulls all of this together). But this time we’re going to do something similar with Node.js. This blog entry is going to position us so we can then take a simple solution and push up to the cloud – as I use Oracle a lot then we’ll be looking at the Oracle cloud as a final step.
To start we need a local instance of node.js. Given the fact it is a small footprint we can pretty much install anywhere. So you’ll need to download Node.JS from the official site, and install it. I’m not going to walk through the installation guidance as it is well documented elsewhere (http://blog.teamtreehouse.com/install-node-js-npm-windows for example). You do want ensure you include the NPM capability (node.js packaging & deployment tool). Make sure that Node is on your path so we can reference the binary without a lots of file paths. You also want to ensure that node.js is up and running.
Next up is to the the Prowl API library that makes interacting with prowl simple and helps illustrate the deployment framework (NPM) used by node.js. So following the link from the Prowl website or go directly here and download the library. If you download the zip file as I did, you’ll find it has a folder called node-prowl-master. You need to unpack this and rename to node-prowl. and run the command
npm install node-prowl
When I first tried to deploy the Prowl API library then I did see an error. This isn’t the API but actually the Node.js installation (atleast on my Windows platform) as you can see:
I found googling using node.js and ENOENT showed up plenty of help to solve errors. In this situation the solution was purely to create the folder. Then re-running the action without problem.
When the npm command works you’ll see something like:
// our very first node program
// get info about the OS
var os = require(‘os’);
// say hello world and include the hostname
console.log(“Hello world, we’re running on ” + os.hostname());
Before we do anything else, lets be a bit clever, to allow us to run our Node script within JDeveloper. This can be done by adding a new Tool through the Tools –> External Tools … menu. Which will display the following screen:
Asa you can see in this image I have already selected New… and walked through the configuration screens, you’ll probably want to use a configuration similar to what I have in the following steps:
So lets take things up a notch and send our mobile device a message. So using the following code, we can use the prowl-api and initiate a message:
var Prowl = require(‘node-prowl’); // pull in the prowl API we deployed with NPM earlier
var prowl = new Prowl(‘your-prowl-key-here‘); //setup your API key
var now = new Date();
// ready to send the message, passing a function reference to handle the response
var message = ‘hello mobile device, the time is ‘+ now.toUTCString();
prowl.push(message, ‘NodeJS App’, prowlReplyHandler);
//function to handle the response from the prowl API lib
function prowlReplyHandler ( err, remaining )
if( err )
var errorStr = err.message;
console.log( ‘I have an error ‘ + errorStr);
console.log( ‘I said:’ + message+ ‘; I have ‘ + remaining + ‘ calls available’ );
Note you’ll need to replace your-prowl-key-here in the above code with you genuine API key registered with the Prowl web app. Then we can run the application, and should see:
Our mobile device will show:
Next steps, in the next post – run through through a cloud hosting of node.js and extend the capability to be a simple service, which will mean packaging ourselves up and other exciting things.