100,000+ hits on TechnoBeans

Thanks guys for your overwhelming responses to my blogs over the last couple of years..

Technobeans has managed to get 100,000+ hits and credit goes to you all who viewed and referred the content to your friends, and colleagues. While this is great milestone, I wish you guys continue to look forward to more blogs, articles, books, open source projects on Python, Java, NodeJS and many more interesting topics to follow..

Occasions like these keep me motivated to say the least.

Thanks again!

Advertisements

Express for Node.js

Express is a simple web application framework for building hybrid web applications. You can render web pages, generate  customized responses and create user-friendly APIs quickly with ease. It just fits the trade with Node.js.

This post covers the installation and hello world example:

Installation:

buntu@ubuntu:~$ sudo npm install express
express@3.1.0 node_modules/express
├── methods@0.0.1
├── fresh@0.1.0
├── cookie-signature@0.0.1
├── range-parser@0.0.4
├── buffer-crc32@0.1.1
├── cookie@0.0.5
├── debug@0.7.2
├── commander@0.6.1
├── mkdirp@0.3.3
├── send@0.1.0 (mime@1.2.6)
└── connect@2.7.2 (pause@0.0.1, bytes@0.1.0, formidable@1.0.11, qs@0.5.1)

Hello World Example:

In the above example:

  • 1. express module is imported and application object is created
  • 2. Object’s get() method is called and callback is set to respond with ‘hello world’
  • 3. When user sends a GET request at port 3000, an event is generated that is handled by callback function(request, response)

Installing Node.js on Ubuntu

I would continue explaining more about Node.js, but for all those folks who do things and understand them, here’s the way to install Node.js on Ubuntu machines..

You need to first install necessary packages like git-core and libssl-dev

sudo apt-get update
sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core

Download the latest source and build it

wget http://nodejs.org/dist/v0.8.2/node-v0.8.2.tar.gz
gunzip node-v0.8.2.tar.gz
tar xvf node-v0.8.2.tar.gz
cd node-v0.8.2
./configure
sudo make install

Check the version after install

node -v

 

Node.js

This is an introduction post to node.js..

Node.js is an event driven, non blocking (async) I/O style software that is used to develop server side implementations. (If you’re a Python fan, it’s like programming in Twisted!). It’s also built on Google’s V8 JavaScript engine. Like other event driven servers, Node.js, runs an event loop and handles the events asynchronously with callback invocations.

A typical ‘ hello world ‘ web server implementation can be found below. Run as: node helloworld.js

In this example,

1. we import module http and create a http server that listens on port 8888.

2. When the user makes a Get request on http://localhost:8888, the web server renders Hello World on the web browser. You can play around with request and response variables as used in the server code.

3. It’s interesting to note that if reponse.end() statement is commented out, the request doesn’t complete and the server hangs. If you press Ctrl+C, only then the request completes and ‘Hello World’ is rendered on the browser. So server developers, beware!

You may ask, what’s this function(request, response) and why it’s anonymous? Well, that’s a motivation for you to read my next post! 🙂