This lesson covers:
Node.js is a fresh server development platform. One of the beautiful things about node is that its written in javascript. There are a lot of little things I like about node.js, (npm, web sockets support, streaming API) but it the main reason we will be using it here is because it is javascript. You can jump into the server side code and tinker around.
The easiest way to install it is to go to nodejs.org/downloads and download whatever pre-built binaries are right for your system.
I do prefer installing from source. It gives me more control over versioning, I can look at the source code if I want, and I think being confortable with compiling/installing from source has made me a better developer. You will need your developer tools installed. I installed xcode and had to enable the make tools in the settings. TODO: find these instructions online.
This might not be the best way to do it. Hopefully, a true system admin will edit this to make it a little more complete or UNIX friendly.
I am hoping you are at least a little familiar with command line.
— Move to the /usr/local directory
cd /usr/local
— Download the source
git clone https://github.com/joyent/node
TODO: git checkout correct stable branch
— configure make
./configure
— make that shit!
make
— ok, now install
make install
See! Totally painless. You should be able to be at any folder in your terminal and type…
node -v
…and see some info on the version you installed. Since version (TODO: find version) you also installed npm, which is node’s package manager. We will get into npm in a little bit.
Express is a light web framework for node.js. I don’t know if its the best, but it is the most widely used, and is now the defacto framework. I find that it is not that useful past 5-6 pages, but thats just me. Node.js is young and we can’t expect to have a django or rails right out of the bag. Someone has to build that (TODO: build django framework for node.js).
You can do a couple different things, depending on how much you are in love with express. It might not be a bad idea to install express globally.
npm install -g express
This allows you to run express commands from anywhere. They have a lightweight build tool that can come in handy for starting projects.
If you are following along with the server code I created for this project, you only need to go to the root folder and type…
npm install
… and npm will take care of the rest. The package.json file tells npm what packages it uses (and describes the project overall. If you make changes, make sure to update your package.json to reflect them).