It’s just data

First Impressions: node.js

Edward O’Connor: Fortunately, Node already has an excellent implementation of the HTML5 parser (by Aria Stewart)

I find it rather amusing that the first thing I encounter is a bug.  This bug was quickly addressed, and I’ve verified the fix.

Actually, that was the second problem.  The first was that if I installed node.js from git, npm wouldn’t install.  The symptoms were that npm would download, install to a temporary directory, attempt to install for real, proceed to remove the temporary directory, and then report success.  Downloading the script, removing the code that removed the temporary directory, running it again, going into that temporary directory, and running make manually resulted in a failure message (simply return code of 1 with no other information) which apparently didn’t result in the installation being reported as a failure.

Here is the installation instructions that actually worked for me (backing up to the stable version):

sudo apt-get install g++ curl libssl-dev apache2-utils
wget http://nodejs.org/dist/node-v0.2.6.tar.gz
tar xzf node-v0.2.6.tar.gz
cd node-v0.2.6
./configure --prefix=$HOME
make
make install
curl http://npmjs.org/install.sh | sh

With that fix in place, I was able to proceed to run the test I wanted:

var http  = require('http'),
    html5 = require('html5'),
    jsdom = require('jsdom'),
   window = jsdom.jsdom().createWindow(null, null, {parser: html5});

var rubix = http.createClient(80, 'intertwingly.net');
var request = rubix.request('GET', '/blog/', {'host': 'intertwingly.net'});
request.end();
request.on('response', function (response) {
  var parser = new html5.Parser({document: window.document});
  parser.parse(response);
  jsdom.jQueryify(window, 'jquery-1.4.4.min.js', function(window, $) {
    $('h3').each(function() {
      console.log($(this).text());
    });
  });
});

Observations:

Next time I pick this up I’ll have to try something larger.


Great to see you taking a look at node.js. I was also very pleased to see Mark Nottingham poke his head in, fix trailers and then write an http tracer with node_pcap!

To learn node.js, I’m working on an HTML5ish Twitter client called Denby: [link] (along with node-twitter https://github.com/jdub/node-twitter, a pretty solid Twitter library underneath) and a DAAP server/client library with web interface.

It’s a lot of fun. I’m getting all the hot flushes I got with Twisted, but it feels so natural in JavaScript because it was built for evented programming.

:-)

Posted by Jeff Waugh at

Sam Ruby: First Impressions: node.js

submitted by ndanger [link] [comment]...

Excerpt from node.js at

Can’t wait to read about your next node.js adventure.

Also...
s/asynchronisty/asynchronicity/g

Cheers.

Posted by Christian Romney at

And I’ll get those HTML5 errors cleaned up soon.

Posted by Aria Stewart at

JSDOM will try to download any scripts it finds, but you can turn that off.

The scripts are executed in a separate V8 context that doesn’t have access to the Node.js APIs, so it shouldn’t be able to read files, open sockets, etc. Regardless, there’s no security architecture, so you do have to be cautious about potential compromises, and if those objects/methods end up being reachable from JSDOM, then anything goes.

Posted by Assaf Arkin at

JSDOM will try to download any scripts it finds, but you can turn that off.

I’m new here, but looking at the JSDOM documentation I don’t see anything that indicates how one would do it.  Anybody care to provide a pointer?

Posted by Sam Ruby at

s/asynchronisty/asynchronicity/g

Fixed.  Thanks!

Posted by Sam Ruby at

submitted by gst [link] [comment]...

Excerpt from JavaScript at

There’s a thread about security where Elijah Insua mentions turning off script execution and provides a code sample:

doc2 = jsdom.jsdom(html, null, {
  features : {
  FetchExternalResources : ['script'],
  ProcessExternalResources : false
  }
});

Thread: [link]

Posted by Greg Reimer at

submitted by gst [link] [コメント]...

Excerpt from JavaScript at

node.js – Interessanter Gedanke

node.js , die erste brauchbare Realisierung von serverseitigem JavaScript (dank Googles V8-Engine), zerbricht ein paar Paradigmen herkömmlicher Webentwicklung. Die offensichtlichen Vorteile liegen auf der Hand: eine einzige Sprache auf Server und...

Excerpt from Markus Schlegel at

Server Side jQuery!

[link]...

Excerpt from Delicious/gfranxman at

Add your comment