{"id":120,"date":"2011-02-21T17:14:27","date_gmt":"2011-02-22T00:14:27","guid":{"rendered":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/?p=120"},"modified":"2011-02-21T17:16:14","modified_gmt":"2011-02-22T00:16:14","slug":"javascript-and-nodejs","status":"publish","type":"post","link":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/javascript-and-nodejs\/","title":{"rendered":"Playing with JavaScript and node.js"},"content":{"rendered":"<p>I really enjoy learning new things in the field of computer science.\u00a0 Recently I have been learning some new computer languages and having a great time into the bargain.\u00a0 Ruby is my favourite, but I&#8217;ve also started playing with node.js which is an asynchronous IO library bundled with an implementation of JavaScript (or ECMAscript) because <a title=\"substack\" href=\"http:\/\/www.plurk.com\/substack\">substack <\/a>has been Plurking about how wonderful it is.\u00a0 I&#8217;m not all that keen on JavaScript so far, partly because I&#8217;m so keen on Ruby and partly because of the criticism of it by <a title=\"Crockford on JavaScript\" href=\"http:\/\/yuiblog.com\/crockford\/\">Douglas Crockford<\/a> in his book <a title=\"The Good Parts\" href=\"http:\/\/oreilly.com\/catalog\/9780596517748\">JavaScript: The Good Parts<\/a>.\u00a0 However he is not totally anti-JavaScript and has spent a lot of time working on its standardisation as described in a YUI Theatre video called <a href=\"http:\/\/developer.yahoo.com\/yui\/theater\/video.php?v=crockford-yuiconf2009-state\">The State and Future of JavaScript<\/a>.\u00a0 (This was very interesting for me, for reasons some people may know, though of course I didn&#8217;t agree with everything he said.)\u00a0 There&#8217;s a bunch of intriguing talks available at <a href=\"http:\/\/developer.yahoo.com\/yui\/theater\/\">The YUI Theater<\/a> which I&#8217;d love to watch.\u00a0 I did watch the <a title=\"Ryan Dahl \u2014 Introduction to NodeJS\" href=\"http:\/\/developer.yahoo.com\/yui\/theater\/video.php?v=dahl-node\">one by Ryan Dahl on node.js<\/a> and I expect I will go back for more.<\/p>\n<p>The computer on my desk at home runs Windows (XP SP3 at the moment) rather than my beloved NetBSD or a Linux variant.\u00a0 Of course my servers run real OSes, but I wanted to work on my desktop machine and so spent a while installing <a href=\"http:\/\/www.nodejs.org\">node.js<\/a>, its package manager and associated packages under <a href=\"http:\/\/www.cygwin.com\">Cygwin<\/a>, which is what makes programming on a Windows machine bearable for me.\u00a0 The node.js <a href=\"https:\/\/github.com\/ry\/node\/wiki\/Installation\">installation instructions<\/a> cover <a href=\"https:\/\/github.com\/ry\/node\/wiki\/Building-node.js-on-Cygwin-%28Windows%29\">Cygwin separately<\/a> and the instructions there worked for me.\u00a0 However I had a problem using the <a href=\"https:\/\/github.com\/isaacs\/npm\">Node.js Package Manager<\/a> to install third-party modules.\u00a0 As described in <a href=\"http:\/\/comments.gmane.org\/gmane.os.cygwin\/124008\">this email thread<\/a>, Cygwin pipelines into gzip can hang in certain environments.\u00a0 I spent hours rebooting, reinstalling and futzing around until I found that thread, which goes on to lay the blame on a &#8220;<a href=\"http:\/\/www.cygwin.com\/acronyms\/\">BLODA<\/a>&#8220;.\u00a0 It turns out that certain antivirus applications can cause this, by hooking themselves into the system call invocation chain in a way which doesn&#8217;t actually work perfectly.\u00a0 I turned my AVG Antivirus Free (v11) off for 30 seconds during the installation of this particular package (called &#8220;<a href=\"https:\/\/github.com\/mikeal\/request\">request<\/a>&#8220;) and the installation went like a dream.<\/p>\n<p>Node.js is young software and under frenetic development.\u00a0 One promising use-case is the implementation of very scalable web applications, where the asynchronous IO model can yield great efficiencies.\u00a0 My interest in it is as a web client, where I hope to use it to retrieve and execute JavaScript from websites whose applications depend on it, but with which I want to interact with programatically rather than manually in a browser.\u00a0 Some such websites (for example <a href=\"http:\/\/www.plurk.com\/API\">Plurk<\/a>) provide proper APIs for this, whereas others, such as Facebook, do not.\u00a0 Facebook requires you to write a Facebook application instead.<\/p>\n<p>A consequence of node.js&#8217;s youth is the immaturity of adjunct libraries for interaction with other services.\u00a0 Although HTTP is treated as a first-class application with built-in support, that support is primitive at this stage when compared with Ruby&#8217;s <a href=\"http:\/\/www.ruby-doc.org\/stdlib\/libdoc\/net\/http\/rdoc\/index.html\">net\/http<\/a>.\u00a0 I&#8217;ve been exploring the available libraries for node, which for HTTP client applications include <a href=\"https:\/\/github.com\/billywhizz\/node-httpclient\">node-httpclient<\/a>, <a href=\"https:\/\/github.com\/tmcw\/node-get\">node-get<\/a>, <a href=\"https:\/\/github.com\/codehero\/node-http-digest\">node-http-digest<\/a>, <a href=\"http:\/\/https:\/\/github.com\/mikeal\/request\">request<\/a> and <a href=\"https:\/\/github.com\/coolaj86\/abstract-http-request\">abstract-http-request <\/a>of which the last two look particularly promising.\u00a0 None of them appear to offer cookie storage between requests, which is something I will need.\u00a0 At the moment I&#8217;m thinking of using one of the available key-value storage libraries which are available to store cookies.<\/p>\n<p>Once one receives the appropriate page from the server, the HTML may need parsing (and there are plenty of HTML parsers for node, such as <a href=\"http:\/\/search.npmjs.org\/#\/html5\">this<\/a>), and scripts therein will need executing (aha! That&#8217;s why I&#8217;m using JavaScript to write the program!).\u00a0 That&#8217;s all in the future.\u00a0 For now, I&#8217;m able to run simple JavaScript programs which fetch pages from websites, and ready to start the real work.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I really enjoy learning new things in the field of computer science.\u00a0 Recently I have been learning some new computer languages and having a great time into the bargain.\u00a0 Ruby is my favourite, but I&#8217;ve also started playing with node.js which is an asynchronous IO library bundled with an implementation of JavaScript (or ECMAscript) because [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[18,19],"class_list":["post-120","post","type-post","status-publish","format-standard","hentry","category-technology","tag-javascript","tag-nodejs"],"_links":{"self":[{"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/posts\/120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/comments?post=120"}],"version-history":[{"count":3,"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/posts\/120\/revisions"}],"predecessor-version":[{"id":122,"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/posts\/120\/revisions\/122"}],"wp:attachment":[{"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/media?parent=120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/categories?post=120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/tags?post=120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}