How To: Install Node Js And Roll Out Your First Project
Friday, 3 September 2010
So after NodeKnockout I have to say I learnt a lot about the simplicity that comes with developing a nodeJs app! A few people have asked me about how easy it is to roll out their own app, and I’ve walked a few people though it, and finally decided it warranted a blog post!
You’ll be walked through how to set up:
- Install NodeJS
- Install Node Package Manager (npm)
- Install the Express framework, and a few other packages
I’m doing this on a mac, but it should be the same on any posix system (linux, bsd, etc) (sorry windows, but if you want to be a serious developer, and .Net isn’t doing it for you, then change your OS)
So lets get this started!
Visit the NodeJS website and download the latest node package. It’ll come in tar.gz format. At the time of writing this, its node-v0.2.0.tar.gz. So I’ll pull it down, and install it!
On the console do:
wget http://nodejs.org/dist/node-v0.2.0.tar.gz tar xvf node-v0.2.0.tar.gz cd node-v0.2.0 ./configure make sudo make install
The sudo is required as node installs /usr/local/lib/
Once thats done, check to make sure you have it installed
node --version => 0.2.0
Visit the NPM site. There is a link to the github repo that has some extra info not on the site. I recommend visiting it and reading the readme..
After you’ve done that, to install:
curl http://npmjs.org/install.sh | sudo sh
And then check if its installed
npm --version => 0.1.27-11
You might have a later version, again this was the latest at time of writing.
Express is a sinatra like framework that wraps nodejs. It looks pretty sexy! It uses Jade by default, which is a HAML like templating language. Very sexy indeed.
sudo npm install express sudo npm install jade
Rolling out a new nodejs app!
Express has a few generators, which makes life easier for all involved.
Go through the project and have a look at the directories/files. The important one there is the app.js file. This file is used to run your new project!
To run your node server run
You can then point the browser at http://localhost:3000 and bingo!
Where to find packages?
There is a good list of hosted Addons & Modules. Or just a bit of googling will come up with a few extras.
In further articles I’ll write a little bit more about how to modify the app, add extra actions, etc.