Month: April 2015

Maps example with Google Maps and Nodejs

Prash's Blog

This is a short piece of code to show maps in a nodejs application.

We will need some 3rd party modules, so install these modules

  • EJS is a dependency for Express.
  • Express is a framework ExpressJS built on top of ConnectJS, it allows robust routing, view rendering, and templating. ExpressJS Details here.
  • GeoHash module is needed to convert geohashes to latitude and longitude coordinates. Geohash is used to uniquely identify a geographical point, it uses latitude and longitude to create a composite string that can be transmitted, stored. Datastores that do not have strong spatial indexing support, geohashes can be used. But having said that, in our application below, there is nothing stopping you from directly entering lat and lon coordinates in url querystring, it is just that geohashes will make the url shorter. Just to note that with a geohash you can trim characters from the right side…

View original post 128 more words

Webapplications with node.js – Jade

iPROFS Technology Blog

In my previous post I described how you can install node.js and how to use express.js to create a webapplication for the node.js server. Now it is time to look into the templating engine – Jade – that express uses for outputting html to the browser.

As I did not have any knowledge yet of jade, it was time for me to do a quick study of jade. As a lot of github projects, the initial documentation is rather sparse, since it only showed an example of the jade template language will be translated into html. But luckily clicking on the github fork ribbon showed some more documentation on github. Basically it looked pretty easy, it’s just html with indentation meaning something and with all the >’s and <‘s. replaced by ‘(‘ and ‘)’. At least that makes it easier to type in html

View original post 1,175 more words

Node.JS & MongoDB – Looping through Collection using core MongoDB library

Technology Discussions by Ajay Singh

As we all know that MongoDB is very good companion to Node.JS because of the linkage with JSON which is common to both the platforms. JSON is an integral part of Node.JS as it is JavaScript and MongoDB stores data in Binary JSON format.

Now the question is how to perform some simple operations like looping through the objects in collection. This article assumes that you have already installed the core MongoDB library using Node Package Manager (NPM).

sudo npm install mongodb

Now the very first step is to declare the variables pointing to the ‘MyDB’ database in MongoDB:

===================================================================================

// MongoDB Connection
var Db = require('mongodb').Db,
    Connection = require('mongodb').Connection,
    Server = require('mongodb').Server,
    BSON = require('mongodb').BSONNative;

var host = process.env['MONGO_NODE_DRIVER_HOST'] != null ? process.env['MONGO_NODE_DRIVER_HOST'] : 'localhost';var port = process.env['MONGO_NODE_DRIVER_PORT'] != null ? process.env['MONGO_NODE_DRIVER_PORT']…

View original post 97 more words

Delegation vs Inheritance in JavaScript

JavaScript, JavaScript...

When asked what he might do differently if he had to rewrite Java from scratch, James Gosling suggested that he might do away with class inheritance and write a delegation only language.

Using inheritance as a vehicle for code reuse is a bit like ordering a happy meal because you wanted the plastic toy. Sure a circle is a shape and a dog is a mammal – but once we get past those textbook examples most of our hierarchies get arbitrary and tenuous – built for manipulating behaviour even as we pretend we are representing reality. Successive descendants are saddled with an ever increasing number of unexpected or irrelevant behaviours for the sake of re-using a few.

Delegation is a technique that promotes code reuse by allowing runtime function invocation in the context of a specific instance – regardless of the hierarchical lineage of instance and function. JavaScript has…

View original post 1,133 more words