Wednesday, 22 January 2014

Back-End NodeJS

NodeJS give me the ability to write back-end code in JavaScript. It's the better framework to build real time applications.We can create applications using pure JavaScript.

Setup Environment

    First thing to do  get NodeJS installed on your system. For installation in Linux link .
After  installing NodeJS we have to setup the following.


  1. ExpressJS -  this will manage the server and the response to the user.
  2. Template engine 
  3. Socket.io - allows for real time communication between the front-end and back-end

Creating Application
    There is two ways to create applications in Node.
      First create a file named package.json in your project directory and add the dependencies . 
 {  
   "name": "login app",  
   "version": "0.0.0",  
   "description": "Authentication",  
   "dependencies": {  
     "socket.io": "latest",  
     "express": "latest",  
     "jade": "latest"  
   },  
   "author": "developer"  
 }  

Navigate to project folder and execute
 npm install  

Within a few seconds, you’ll have all the necessary dependencies downloaded to the node_modules directory.
            The other way is using ExpressJS we can create application follow the link.

         Developing the back end create a file app.js with the following core expressjs code.

 var express = require("express");  
 var app = express();  
 var port = 3000;  
 app.get("/", function(req, res){  
   res.send("It works!");  
 });  
 app.listen(port);  
 console.log("Listening on port " + port);  

To initialize the application execute:

 node app.js  

Now the server is running go to browser and open http://localhost:3000/ and see:
'it works' 
                           Also we can develop the front end using static and socket.io.
  To see my application  click here .
My code can be found here.

Tuesday, 21 January 2014

NoSQL with MongoDB

NoSQL is designed for distributed data stores where very large scale of data storing is needed. It is different from traditional relational database management systems and are developed to manage data that do not necessarily follow a fixed schema. 
This avoids joins and are easy to scale.

Categories of NoSQL database
  • Key-value store (eg. Voldermort, Tokyo Cabinet, Riak)
  • Graph (eg. FlockDB, AllegroGraph)
  • Big tables/column families (eg. Cassandra, Hypertable ) 
  • Document store (eg. CouchDB, MongoDB)
Now we discuss about MongoDB
Setup MongoDB

    Let's see how to get started with MongoDB. Get the installation instructions from here.
    After the MongoDB installation, your database ready and starts running on your system. You can check if your system is running MongoDB, by typing mongo in the Terminal. If it is, there will be shell version number and some other details of MongoDB, printed on the terminal. 
     Let's make Mongo as back-end in our project. Here i created a paint-application using flask and
MongoDB  .The same application in Django link.

To get MongoDB in Python we need install module PyMongo by typing
  
$ pip install pymongo 

To connect to the database, we create a database instance- a connection object by including the following in our python logic.

 from pymongo import Connection  
 conn_obj = Connection()  
 db = conn_obj.our_db_name  

Now we are ready to use our MongoDB database through the python code. 

 db.collection_name.find()  

It's also possible to get the specific item in the collection. 

 db.collection_name.find_one({"color": "Orange", })  

Reading all the documents of the specified kind, is by, 

 db.collection_name.find({"color": "Orange", })  

More option can be found here.

Friday, 17 January 2014

Paint app in Django

I have modified Paint app using Django frame work. Only the back-end is changed other things remains same.
The URL configuration used in Django is url.py.

 from django.conf.urls import patterns, include, url  
 from mysite.views import home,current_datetime,gallery,save,load  
 urlpatterns = patterns('',  
   url('^$', home),  
   url(r'^time/$', current_datetime),  
   url(r'^gallery/$', gallery),  
   url(r'^save/$', save),  
   url(r'^gallery/([^/]+)$', load),  
 )  

Database used is PostgreSQL

The other important thing is views used in Django which  renders the template ,respond to GET and POST request ,and also inserting and retrieving data into database. The code can be found here