Some notes about node.js

I've been a perl programmer for a long time, and it has served me good. As computers and web browsers became faster, using Javascript for web pages and lately, web applications, became important. For some time I've been using Javascript when and whereever it made sense, but mostly for client side "sugar". Perl is a great language, has a great community with plenty of high quality libraries ("CPAN"). Most scripting languages are appreciated for their simplicity, and less for their speed. For common tasks they are typically quite speed, usually because of low-lever C libraries running beneath it. If you ever had to run some "inner loops" in most of them, you realize there's usually a limit to what makes sense to do in such high-level scripting languages. I've personally "prototyped" a backgammon position evaluator (identifying all legal moves), a poker hand evaluator (finding the best hand from X cards, like holdem, omaha, stud or whatever) and a high frequency trader bot, evaluating positions, exit and entries on a per-tick basis. The great thing about the scripting languages is that they allow you to spend more time on the core problem, and less time convincing the compiler about all kinds of details in your data and algorithms. For the examples I mentioned (and more), rewriting in C/C++, either parts of the whole part of the application usually makes sense. Most of the scripting languages interface quite easily with C/C++.
When making web applications (or "rich" web pages), one would typically use a scripting language on the server side, tied together with HTML+Javascript on the client side. Over the last decade, Javascript itself has matured as a language standing on it's own two legs. At the same time Javascript became useful for more than just simple DOM manipulation and simple browser event handling. Javascript has also became fast. Faster than most scripting languages in fact. Today one could argue that with it's various JIT implementations, Javascript is probably one of the fastest scripting languages existing. At least if you focus on tasks that do not simply call into low-lever C libraries of the traditional scripting languages.
Then Google released V8, enabling really fast and efficient javascript running outside of the browser environment, for instance on servers. The people behind node.js and possibly others saw the potential, and wrote frameworks building on V8 to allow really fast and efficient server-side javascript applications. When I worked with massively multiplayer games in the nineties, I spent lots of time with low-level C/C++ programming for efficient network communication. We even had "high-level" C++ frameworks to make things a bit easier (ACE - Adaptice Communications Environment). Comparing what we had then with what you get with V8+node.js, well, it's not just fair. At least as far as writing web servers and clients goes.
Node.js is built on top of V8, and includes lots of useful javascript libraries and interfaces, allowing you to write blazingly fast server side javascript code. It's now possible to build great applications, using one language, both server-side and client-side. As I mentioned Perl has served me great, but the possibility of using the same language (and datatypes) both server-side and client-side meant that for me it was time to brush up on those javascript skills, and specifically learn more about node.js .
Installing node.js from github is straightforward. Clone it from github, run ./configure then make install. Works just fine. Node.js comes with a few standard libraries, enough to get you going, but probably not everything you need to write real applications. Within a short while you probably need to download some code that others wrote. The github node.js page has it's own page which lists popular node.js libraries. It certainly has been possible to write server-side javascript prior to node.js, and if you have, you probably know the ins and outs of javascript module packaging. I didn't though, so I'm still learning the basics.
Even though I've just gotten started, it has been a very positive experience so far. I've stuck around, spending a little time now and then, trying to keep pace with both node.js, it's libraries (the few I use) and how things are packaged. The node.js chatroom on IRC (Freenode) has been very helpful, and is where (I guess) most of the node.js and library authors hang out.
After I had juggled around a bit, pulling external libraries into my own projects, and trying to keep things updated, I learned about some node.js package managers. There were two, "kiwi" and "npm". Some modules worked, some did not. Either because of my ignorance, or because of bugs. After a short while, npm seemed to become the "official" node.js package manager. My memory might be wrong, but I believe npm used to be a shell script, and there were examples where npm was actually used to install node. Later it seems npm has been rewritten to run in node, basically requiring node to be installed before the package manager can be used.
I recently also did (yet another) upgrade of node and the libraries I use, when I ran into more issues related to node.js and package managers. My own ignorance again gave me some trouble, as it seems that when I though I had upgraded node to the latest version, I really had not. Probably forgot to run ./configure. Since my version of node was really old (like a couple of months; node is moving fast), npm didn't behave, and things got a bit messy (at least from my perspective). During the figuring out phase, I learned about nvm and nave, which supposedly allows one to host different versions of node, controlling which version a certain application runs under. I couldn't quite get nvm working, so I tested nave. As part of my cleanup process, I had already removed the old version of node; I wanted nave to manage my node installations. I tried installing nave with npm. Of course npm requires node itself, so npm would not run. Luckily, nave is just a shell script, so it's pretty easy to download (clone it) from github and install it manually. For some reason, nave still seems to require an existing installation of node to be used. All these circular dependencies keeps messing with my head, so I took a long step back and started from scratch.
If you just want a centrally installed node, with npm, here's what I did:
- Clone node from github, ./configure, make install
- Clone npm from github, make install
I also learned that a package I had used earlier, named connect, had been split into two packages, where connect was the library part and "spark" was the new command line to launch the connect-based application I'm using for learning all this stuff. After upgradeing node and npm, everything seemed to work fine, and installing the two node modules were simply "npm install connect" and "npm install spark". Had I managed to upgrade node correctly, npm probably would have "simply worked" in the first place. Now I know. :-)
Post new comment