Nodejs Simplified HTTP Request

Posted on April 15, 2012


In order to utilise resources already available on the internet, such as websites it is necessary to have a system in place that is capable of making http request.  This enables users of AgNetPro to query information such as weather conditions that is available on external websites/database.  This will hopefully operate similarly to frontlinesms trigger function.

The Request module for Nodejs by Mikeal Rogers  proposes the simplest way possible to make request calls.  Lets install the module and give it a run.

The  Request module was installed through npm –  $ npm install request – and the super sample example in the file worked out of the box.  Changing the url to point to FrontlineSMS http trigger, connection was verified from Nodejs to Frontlinesms, this was not possible in AgNetPro system before as all Nodejs – FrontlineSMS connection was initiated by FrontlineSMS (screenshots to be uploaded which will explain the problem that this solves).

Now for a suitable weather api...

Google's weather api is an undocumented weather api for all major cities in the world (programmable web google's secret weather api).  The api was specifically designed for creating apps (programmable web - google's web api directory ).  The secret weather api is available in xml format.

(Google search google weather api nodejs -

Nodejs google - weather module - accepts city name and date and returns weather forecast 
Currently AgNetPro queries weather api, weather conditions is returned in xml format, however, must be parsed before conditions can be returned to user (screenshots will be uploaded).

Problems currently reported with jsdom
 a required library for node googleweather.  

Error message:


    features   = JSON.parse(JSON.stringify(window.document.implementation._fea


TypeError: Cannot read property ‘implementation’ of undefined

    at /**/****/node_modules/jsdom/lib/jsdom.js:171:59

    at Object.env (/**/****/node_modules/jsdom/lib/jsdom.js:262:5)

    at Request._callback (/**/****/node_modules/googleweather/lib/googleweather.js:39:10)

    at Request.callback (/**/****/node_modules/request/main.js:119:22)

    at Request.<anonymous> (native)

    at Request.emit (events.js:70:17)

    at Request.<anonymous> (/**/****/node_modules/request/main.js:521:16)

    at Request.emit (events.js:67:17)

    at IncomingMessage.<anonymous> (/**/****/node_modules/request/main.js:483:14)

    at IncomingMessage.emit (events.js:88:20)