As promised, I now begin the series of tutorials on the amazing new technology called Node.js which I have started working on some time back. Though I don’t promise that the methods I suggest are the best way to achieve the required goal, but I can guarantee that they work.
There… thats it. In its entirety, node has a minimalistic core which provides it the amazing flexibility to be extended. There are many amazing features in node that you can read about in its official documentation.
Before you proceed, I strongly recommend you read THIS tutorial and TRY all the examples given in it to get the idea of how node works with asynchronous callbacks. Though it would be better if you did the whole thing step by step yourself, below is the link to my github profile where you can download the completed example 😛 .
In this series, I will be emphasizing on building a full fledged web-application with following features:
Basic design of an application
Creating an MVC architecture using Express framework
Using Twitter Bootstrap to get better looking widgets with JADE templating engine
User authentication, both custom and using services like twitter, facebook, google etc.
Sending emails from the node application
… and anything I think I found some difficulty looking up and is worth mentioning.
Without further ado, lets get to it.
To proceed further you should have Node and NPM (Node Package Manager) installed. All the examples have been tested on Ubuntu 11.10.
– Using npm, install expressjs globally by issuing following command
After this is installed, you can create an example application called ‘myblog’ by just punching in following command
Express will create a directory called ‘myblog’ and a bunch of files in it. You dont need to know what exactly those are there for right now. I will be explaining that later.
Now navigate into the ‘myblog’ folder and type in
You will find some error saying – ‘Cannot find module ‘express’. Right. But you just did create this very folder by using express only. Turns out that this application requires express locally and hence you have to install express locally for this module also. This is true for any node module. The dependencies have to be satisfied locally. Ok, so what do you do now? Take a look at ‘package.json’ file.
This file contains all the dependencies that your application requires and it will have two entries – express and jade. Now just type in: