Node.js might be the most exciting single piece of software in the current JavaScript universe. Ryan received standing ovations for his talk and he really deserved it!
I tried Node.js last week and I was quite impress. Truly, Node.js has the potential to change the way we do I/O. Basically it’s an evented programming concept build on underlying stack of Python and C++ while using Google’s V8 (JavaScript Engine) as an interfacing language capable of performing network programming (using polling) in different way. Here are some of the key design goals of this technology:
No function should direct perform I/O (Use Callback to do so)
Stream everything, never force the buffering of data (Somewhat like comet)
Have built-in support for the most important protocols: HTTP, DNS, TCP
Support many HTTP features: Chunked requests, Keep-alive, Hang Requests for comet applications
Bridge API somewhere between flexibility of client side JavaScript and old Unix tools
Platform independent
Example:
Simple Twitter Client I wrote last week:
var http = require("http"),
sys = require("sys");
var connection = http.createClient(80, "twitter.com");
var since_id = '';
var interval = 0;
function getTweets() {
var url = "/statuses/friends_timeline.json";
if (since_id != '') {
url += "?since_id=" + since_id;
}
var request = connection.get(url, {
"content-type": "application/json",
"User-Agent": "NodeJS HTTP Client by Infynyxx",
"host": "twitter.com",
"Authorization": "Basic " + Base64.encode("infynyxx:*****")
});
request.finish(function(response) {
var responseBody = "";
response.setBodyEncoding("utf8");
response.addListener("body", function(chunk) {
responseBody += chunk;
});
response.addListener("complete", function() {
var tweets = JSON.parse(responseBody);
if (tweets.error) {
sys.puts("Error: " + tweets.error);
}
else {
var length = tweets.length;
if (length > 0) {
sys.puts("Getting new tweets...\n");
sys.puts("Number of new tweets: " + length + "\n");
var str = "";
tweets.reverse();
tweets.forEach(function(element, index) {
str += element.text + "\n";
str += element.user.name + "\n";;
str += element.created_at + "\n";;
str += "*************************\n";
});
sys.puts(str);
}
}
});
});
setTimeout(getTweets, interval);
interval = 300000; //5 minutes
}
getTweets();
There’s this overemphasis on reusable software where you never get to open up the box. It’s nice to have these boxes but, almost always, if you look inside the box you can improve it and make work better once you know what’s inside the box. ~ Donald E. Knuth (Excerpt from Coders At Work.)
Second excerpt I posted from the book, Coders At Work that has so deep meaning.
Even though we use so many different libraries and APIs both lower and higher level, if we don’t know what these APIs and libraries do or how they work then, it’s just like using one of those anonymous black boxes with lots of magic.
I haven’t used PostgreSQL and TokyoTyrant so, can’t say much about them. And technically, I really don’t think that one should compare MySQL which is relational database with document based non-relational databases like: CouchDB and MongoDB.
In my opinion, MongoDB out-performs CouchDB in terms of querying, insertion and ease of usage but CouchDB’s support for MVCC and transaction are quite interesting. One of the crons of MongoDB is it’s data size grow at freaking high rate.
Thoough great to see that, NOSQL (NOt Only SQL) is on full swing.
Currently, I’ve been doing some stuffs using MongoDB. If you don’t know or haven’t use it, it’s a document based key-value database systems, that means it’s fundamentally different from traditional DBMS like MySQL, Oracle.
Systems like MongoDB along with similar technologies like CouchDB make significant use of MapReduce. MapReduce is basically a two step process consisting of Map and Reduce where Map is used for reducing a dataset to smaller sub-sets while Reduce is used for for some specific operations into that mapped or grouped data. You can find more information about it all over the web.
Since, PHP driver MongoDB does not provide any specific MapReduce API, I’ve created mine own using MongoDB::command. You can find it @ Github.