Tropo is part of CiscoLearn More

Naked Node.JS

Posted on December 14, 2010 by Adam Kalsey

Mark Headd recorded an awesome screencast on getting Tropo running on Node.js using the Tropo Node.js library.  While libraries make code easier to write, I wanted to see what was happening under the covers when writing a Tropo application using Node.js without any magic.

This experiment was easier that you may think!  Since Tropo speaks JSON natively, all you need to do is spin up a node.js server like the hello world demo on the node.js home page. Next substitute “application/json” for Content-Type and send Tropo JSON text in place of hello world as shown below:

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'application/json'});
res.end('{"tropo":[{"say":[{"value":"This call is running from node J.S. Have a nice day. Goodbye."}]},{"hangup":null}]}');
}).listen(3000, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3000/');

Next, deploy this script to your node.js hosting provider or run Tunnlr as demonstrated by Mark and create a new Tropo WebAPI application pointing at the deployed URL.  Now call your application and listen to Node.js in action.

There you have it – Naked Node.JS!

Leave a Reply