I am Hack Sparrow
Captain of the Internets.

Archive for January, 2012

MongoDB with Node.js

MongoDB and Node.js belong to the same league - new age Web technologies that are shaking up the world of Web development. Both of them are revolutionary alternatives to the traditional technologies like MySQL and PHP. Combining Node.js and MongoDB could be the very best option for your next website or app. Now the question is how do you use MongoDB with Node.js? Node.js has a huge collection of excellent module for many many purposes; naturally there ...

Mongoskin Tutorial with Examples

Mongoskin is probably the most developer-friendly MongoDB driver for Node.js at the moment - it is asynchronous and has a clean looking structure. But its docs are not that developer-friendly (the effort is much appreciated though) - no good examples or explanation; probably because English isn't the author's first language. After realizing that the Mongoskin docs may ...

Detect Browser / User-Agent in Express.js (Node.js)

In Express.js the details of the HTTP User-Agent making the request to a URL is available in the req.headers object's user-agent property. [code] req.headers['user-agent'] [/code] Node.js will not be able to detect the browser if it doesn't have access to the req object, so the detection process should be done in a route handler or through one (pass the req object). In this example, ...

MongoDB – Add Users and Authenticate

Before you add users to databases, you need to add admins to the MongoDB server. If the server is not running with the --auth option, all you have to do is call the db.addUser() function on the admin database. If it is running with the --auth option, you need to select the admin database and identify yourself as a valid admin. [code] > use admin > db.auth('root', 'w00t') ...

JavaScript – Check Object Types

There are times when you want to know the object type of an instance in JavaScript, whether it is an Array, or a Function, or an Object, a String etc. There are two flavors to doing that, one involves the use of the instanceof operator, the other involves stringification of the object's prototype. Follow the examples below, I show both the techniques. First create these variables: [code] var a = []; var o = {}; var s = ''; var n = 42; var f = function() {}; ...