Saturday 4 December 2010

Tutorial 0: Set up node and the various tools.

Introduction:

I've recently managed to crash my copy of linux. One of the system updates made the windows ubuntu installer useless. I've tried hacking around to get it to work to no avail. Here's a quick tip: wubi is useless, don't use it. (As a side effect the boot loader is broken and win7 won't start anymore. I'll wipe the drive once my back up external drive arrives on monday and start from scratch again)

I've got a fresh copy of USB boot ubuntu and I have a self imposed deadline for sunday on kicking out a proof of concept game with nodeJS. This leads me to re install all the software I'm going to use to develop with nodeJS. Seeing as I'm nice I'll walk you guys through it.

About nodeJS:

I'm not here to tell you why you would want to use nodeJS because its simply awesome. Enough said.

Linux:
First things first. Your going to need to get a copy of Linux if you haven't got one already. nodeJS is server side technology and to run this server you need it to run on a linux machine. I would recommend the wubi installer but it's horrible.

If I guide you to ubuntu installation you should be able to grab a liveCD and append a partition to your drive to install Linux. Simply boot from the live-CD and install it. It should be "simple". If you get something other then Ubuntu then your on your own (I'm installing Fedora and its much more of a pain)

nodeJS:

Grab a copy of 0.2.5 (in linux of course). Simply double click on it and extract it your location of choice. As with any software the first thing we do is look for a useful readme file, you'll find it in node-v0.2.5/README.

  ./configure
  make
  make install

We assume by now that you've opened Applications -> Accessories -> Terminal or wherever the terminal is in your Linux distribution (I'll keep assuming your using Ubuntu from now on.). An easier method is to open the terminal by (use ctrl+alt+F7 to escape) pressing ALT+CTR+F1.

We assume you know how to use ls & cd to navigate to your /node-v0.2.5 folder. If you've unpackaged it in the default downloads folder it can be found with

  cd Downloads/node-v0.2.5

So since we _read_ the readme file we know what to do:

  ./configure

Make sure your inside the node folder. Now we most likely we hit a error saying we don't have a c++ compiler. Oh dear where do we get one? We use the powers of apt-get

  sudo apt-get install g++

Lets try to configure again? We get past the c++ compiler and now it tells us we dont have openSSL development packages. By the powers of apt-get:

 sudo apt-get install libssl-dev

We run configure again. It tells me that it hasn't found port.h, sys/event.h and kqueue. I don't think we care about that so let's make node

  make

We get a gigantic wall of text telling us what files were running and eventually we have compiled & linked all the c++ files that nodeJS runs on. It should finished with " 'build' finished successfully 3m4.5s" telling us that we succeeded. Of course your installation is either faster or slower then mine. Feel free to brag about that in the comment.

We should make the installation file and then were finished

  sudo make install

I had an issue on my copy where I need to use sudo to get root permission so I can make folders. It might be unnecessary for you but there is no harm.

So we have node installed. Just run `node` within your terminal (dont do it in the virtual ones under ctr+alt+f1-6 it breaks their formatting). It should show you the ">" prompt and let your write JS at it. For example "console.log('show me text!');" will work. It's not very interesting though. Your better off closing it (surely you must know ctrl+C) and running the tests. I would actaully advice running the test for most thing you download.

  make test

Mine throws only two errors. It can't find the curl command and some hash is not equal to some other hash. 137 tests pass so I'm fairly confident my copy of node works.

It would probably be worth while to kick open a text editor and dump the hello world sample into it from the nodeJS website. Save it as a usefuly descriptive name like "helloworld.js". Navigate to the folder (Remember "cd .." moves up a folder)  and 


  node helloworld.js


Now lets look at your server


Getting an awesome HTML5 browser:


Just pick one : Chrome 7, Opera 11, Firefox 4 beta

Enough said. Pick one.

Get a real IDE:

To me there are only two choices : Netbeans & WebStorm. If you actually want to search around yourself feel free to.

I'll walk you through WebStorm. Download and unzip it. Then go to the /bin folder and run "webide.sh". Double click and select run in terminal. It will tell you no JDK was found.

So lets go Applications -> Ubuntu software center and hit "sun java jdk" in the search bar. Pick up "Sun Java(TM) Development Kit (JDK) 6" and wait a while.

6 hours later. 


Ok I'm working on getting Web Storm to recognize the Java development kit. I forgot Linux was _this_ manual. Good luck installing it. I got it working eventually, I'm sure you will as well :)

Oh netbeans is real easy to install. Go with that if you want.

Set up Git Hub:


Using git hub is a great way to store your project online. Its version control and allows it to be shared with the open source community. We are writing nodeJS projects now so let's keep them open source and have the community grow.

Just create an account and then look at the help page. Create a repository for you work and if your using WebStorm you can create a new project directly from the repository you made.

Now we're ready to go I think.

Good luck.