Saturday, September 20, 2014

Adventures in Web Development: Getting Started with node.js

After being a Web Dev for over 3 years now and still using primarily procedural coding techniques, I'm feeling pretty behind the curve. I've never felt good about my skills but it's become apparent that I won't get better unless I put in the effort to do something about it. To help with this, I'll be digging into some of the current tools of the trade to put together some neat hobby projects.

Arguably one of the biggest must-have tools to come out in recent years is node.js. It's non-blocking I/O model has been proven to save a lot of network resources and to improve application scalability.

I wanted to start my first project with Bootstrap. Bower is a really easy way to pull in all of the Bootstrap files into my project folder. To get Bower, I needed node.js for its npm package manager.

I'm using Kubuntu for my dev environment but this tutorial could apply to any ubuntu-based distro. The steps below were heavily inspired by this blog post.

1) Get Compiler
To use node.js, we need to be able to compile it from source. A compiler is available from the "build-essential" package. 

Update your packages and then install the "build-essential" package:
sudo apt-get update 
sudo apt-get install build-essential -y
 
2) Get Git
Installing Git is a simple command:
sudo apt-get install git -y 

3) Get Python and libssl
node.js depends on Python 2 which is available via the packages:
sudo apt-get install python -y
 
If you want to use TLS/SSL encryption, you will also need libssl:
sudo apt-get install libssl-dev -y
 
4) Get node.js!
At last we can install node.js. Be sure to check the current version on their site before continuing. First we'll use Git to clone the GitHub repository for node.js onto our system. We'll put it in /usr/local/bin to make it globally available for the user.

cd /usr/local/src
sudo git clone git://github.com/joyent/node.git
 
Now go into the cloned repository and check out the latest version (replace the letters after 'v' with the version numbers):
 
cd node
sudo git checkout vX.Y.Z 

With the version checked out, we need to configure it to make sure we have the dependencies installed:
sudo ./configure
 
Everything should report OK. If not, check any dependencies you're missing.
At this point, we have all of the resources we need to compile and install node.js:
sudo make
sudo make install 

Finally, node.js is installed! You can check it in the command-line by doing a quick version check which will return the version number you just installed:
node -v