Tuesday, November 29, 2011

Node.js for Java developers


From the summary:
Node.js untangles concurrency by replacing the Java platform's standard, multithreaded approach with single-threaded, event-driven I/O. In this article, Andrew Glover introduces Node.js and explains why its event-driven concurrency has sparked so much interest, even among die-hard Java developers. He then shows you how to leverage Node's Express framework, Mongolian DeadBeef, and MongoDB to build a concurrent, scalable, and persistent web application.

Saturday, November 26, 2011

Node v0.6.3 is out

Looks like NPM (Node Package Manager) is now included! Wonder if this has any effect on local vs global packages...?

Monday, November 14, 2011

The Node Beginner Book


Running through The Node Beginner Book tutorial by Manuel Kiessling.

The tutorial is a well written introduction to Node. Manuel does an excellent job of starting with a simple server, then incrementally refactoring and adding functionality. Along the way, the reader is introduced to routing, dependancy injection, and importantly blocking vs non-blocking code.

Sunday, November 13, 2011

Installing Node


I've got several goals in mind for setting up an environment for running Node:
  • I want to focus on learning Node, not on making things work.
  • Less important, but it'd be nice to be able to make a smooth transition to a production environment.
While it looks like people have got Node running on Windows, it sounds like other parts of the system, like npm (Node Package Manager) can be troublesome.
With all this in mind, I figured the best bet would be to use a virtual machine (VM) to run a Linux server.
  1. Download & install VirtualBox
  2. Download Ubuntu Server, in my case, Ubunto Server 11.10, 64bit. I ended up making a bootable CD, which may have been uncessasry -- I think VirtualBox can install directly from the ISO image.
  3. Run VirtualBox and create a new VM. I specified 512 MB memory, 12GB disk.
  4. Start up the new VM, and install the minimal version of Ubuntu Server.
  5. After rebooting, install some packages
    apt-get -y update 
    apt-get -y install libssl-dev openssh-server git-core 
    apt-get -y install pkg-config build-essential curl gcc g++
  6. I want to be able to share folders between the host system and the VM -- This requires VirtualBox Guest Additions. I ran into problems doing this automatically, but succedded via command line: see https://forums.virtualbox.org/viewtopic.php?t=15679 for details
     // Install Guest Additions (from VM Devices menu)
    sudo mount /dev/scd0 /media/cdrom
    cd /media/cdrom
    sudo sh ./VBoxLinuxAdditions.run
    // no X11 display, expect windows system drivers error...
  7. Configure port forwarding for ssh & http, so I can ssh into the VM & browse
    • VM Devices, Network Adapters, Advanced, Port Forwarding... Add rules for
    • Host Port 8080, Guest Port 8080
    • Host Port 22, Guest Port 22
  8. Install Node. Rock-Solid Node.js can be used as a reference.
     mkdir /tmp/node-install
    cd /tmp/node-install
    wget http://nodejs.org/dist/v0.6.1/node-v0.6.1.tar.gz
    tar -zxf node-v0.6.1.tar.gz
    cd node-v0.6.1
    ./configure
    make -j 2
    sudo make install
  9. Install NPM
     curl http://npmjs.org/install.sh | sudo sh
  10. Set up shared folders
     // Add node.js folder to Shared folders (VirtualBox menu)
    mkdir /home/mike/node.js
    sudo mount -t vboxsf node.js /home/mike/node.js // add to /etc/rc.local 

Saturday, November 12, 2011

Why Node?


From the Node wiki
Node.js is a server-side JavaScript environment that uses an asynchronous event-driven model. This allows Node.js to get excellent performance based on the architectures of many Internet applications.
I used to feel that JavaScript was a toy language, only good for web page eye candy. I've got to admit that it's idioms and patterns have grown on me.

I like the idea of being able to use JavaScript on the server side of things, as well as some of the performance aspects.

Plus I just found out about a hacker-friendly, Linux based embeded board that encludes Node: the BeagleBone. Given my interest in small systems (like Arduino, etc), it seems like a good path to explore.