Getting started with node.js on Windows
The title is somewhat misleading. As of right now, node.js doesn’t run on Windows. You have to run it on some kind of *nix/BSD based system. But there is a somewhat low footprint way to run it and play around with it on your Windows box.
Step 1 – Download and install VirtualBox orVMWare Player. I chose VirtualBox. It’s free, and supports 64-bit guests.
Step 2 – Download The Turnkey Linux core appliance and unzip it somewhere. This handy little virtual machine is based on Ubuntu and give you a basic command line environment with networking.
Step 3 – Import the Turnkey core appliance into VirtualBox.
Choose the .ovf file in the Turnkey directory you unzipped earlier.
Click next and review the settings, making any changes as you see fit. The defaults should work fine. Then click import.
Once Virtualbox finishes importing the virtual machine, you can start it up.
Assuming your network is configured correctly, the virtual machine will grab an IP from your DHCP server and be ready to go.
Step 4 – At this point you can either SSH into the virtual machine or you can connect using the web shell at the address indicated in the startup screen. Initially you can connect using as the root account with no password. You are almost ready to start installing node.js. First type “apt-get update” at the command line to make sure you have all the latest package information.
Step 5 – Install the developer tools you need to get and build node.js. Node.js isn’t packaged as a binary, you have to build it from source. Luckily it includes it’s dependencies and is pretty easy to build. But first we need to get a compiler. Type “apt-get install build-essential” and hit return. A lot of text will fly past, if it asks you if you want to go ahead press “y”.
Step 6 – Install Git. Now you’ve got a compiler installed, we have to install git so we can fetch node.js from the repository. At the command prompt type “apt-get install git”. Once that is complete, type “apt-get install git-core”.
Step 7 – Clone the node.js Git repository. If you want to put node.js is a specific directory, go ahead and make it then “cd” into the new directory. At the command prompt, type “git clone git://github.com/ry/node.git“.
Step 8 – configure the source for building. type “cd node” and change into the node directory that Git created. Type “./configure”. You may see a few “fail” messages. Don’t worry about them.
Step 9 – Build node.js. Type" “make” at the command prompt. Get a sandwich or a nice cool drink. It doesn’t take very long, but it’s not very exciting unless the Matrix screensaver is your favorite screen saver.
Step 10 – Install node.js and start build applications. Type “make install” once the build is complete. Once that is complete,you can type “node” at the command prompt and you should see the standard help information fly by.
Building a node module or application is beyond the scope of this short tutorial. I suggest reading up at the Node.js site.
Goals for 2010
So I’ve been mulling around what I want to do, at least in terms of my development skills and community type stuff, in 2010 (The year we make contact). I figure if I blog them up here, I can refer back to them and check on my progress at the end of the year.
- Help out with the MVC Turbine docs
- Finish my Ringbinder project and release it
- Write a simple little app for use at home in either Clojure or Smalltalk
- Continue to learn Python
- Write a small app that runs on the Google App Engine
- Write a blog post, either here or on my work blog, at least once a week
- Redesign this blog
- Work on and launch the coderdads.info site I’ve had in mind for a while
I’m sure I’ll come up with more as the year progresses and I, hopefully, finish up these tasks.
Modern JavaScript Development: Scope
After hearing an interview Scott Hanselman did with Scott Cate about JavaScript a while ago, I decided to use one of my presentations into a screen cast. In this two-part screen cast, I cover how scope works in JavaScript and how we can use object literal notation to fake namespaces.
Making JavaScript Less Painful part 1
Making JavaScript Less Painful part 2
I’m still finding my way around screencasts. Eventually I’ll upload these to vimeo, screencasts.com,, and youtube as well as making them embeddable and providing embed code.
Modern Javascript Development: constructors and objects
JavaScript doesn't have a "class" keyword or any formal class construct. Instead, functions are 1st class objects. When you write a function, you are essentially writing a constructor for a new object.
Here we are defining a object constructor called "newClass" and assigning some member values.
-
function newClass() {
-
this.name = "newClass";
-
this.options = {size:42};
-
};
-
-
var myInstance = new newClass();
-
alert(myInstance.name);
-
alert(myInstance.options.size);
You can also specify arguments for the constructor just like any other function and assign the argument values to the objects members.
-
function newClassInitialzed(name, options) {
-
this.name = name;
-
this.options = options;
-
};
-
var anotherInstance = new newClassInitialzed("John", {size:42})
-
alert(anotherInstance.name);
-
alert(anotherInstance.options.size);
So what happens if you don't want to pass the name and options to the constructor every time? You can specify defaults for the member variables values using the logical OR ( || ) operator in JavaScript. The logical OR operator has a short-circuit which always returns "true" if the first argument is true.
-
function defaultArgValues(name, options){
-
this.name = name || "unknown";
-
this.options = options || {size:42};
-
};
-
var defaultArgsInstance = new defaultArgValues();
-
alert(defaultArgsInstance.name);
-
alert(defaultArgsInstance.options.size);
Since functions are first class objects, we can pass them as arguments in our constructors as well.
