Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
#!/usr/bin/env node
var YUI = require("yui3").YUI;
debug: true
}).use('node', 'io', function(Y) {
//Messing with the main page..'title').set('innerHTML', 'Digg News Headlines');
//Creating the list that we will append the remote data to
var ul ='body').appendChild(Y.Node.create('<ul></ul>'));
//Creating a sandboxed instance that we will bind to the remote page that we fetch
YUI().use('node', function(remotePage) {
//The page we are fetching
var url = '';
//This will call io under the hood and get the content of the URL,
//It will then dump the content of that page into this sandboxed document.
remotePage.fetch(url, function() {
//Get all the news items from the remote page.
var newsItems = remotePage.all('#story-items h3');
//Iterate them
newsItems.each(function(n) {
//Import this "A" node into the outside instances document
var a = ul.importNode('a'), true);
//Clean up the relative URL's of hrefs
a.set('href', '' + a.get('href'));
//Append the new node to the list
//Now, we can print the "outer" instances html and drop it to the screen
<title>Digg News Headlines</title>
<a class="story-title" target="_blank" href="">Is college a bad investment?</a>
<a class="story-title" target="_blank" href="">29 Meals Where The Presentation Is More Important Than The Actual Food Itself | - c...</a>
<a class="story-title" target="_blank" href="">Famous Logos with Hidden Images</a>
<a class="story-title" target="_blank" href="">Nokia replaces CEO with Microsoft exec to save itself</a>
<a class="story-title" target="_blank" href="">14 Incredible Wood Sculptures</a>
<a class="story-title" target="_blank" href="">A look at Apple&#039;s updated iPhone Configuration Utility</a>
<a class="story-title" target="_blank" href="">They Won&#039;t Even Know What Hit &#039;Em [Pic]</a>
<a class="story-title" target="_blank" href="">Blow Job Supplier Nailed by UK Electronics Law</a>
<a class="story-title" target="_blank" href="">6 Movies That Didn&#039;t Realize They Let The Villain Win</a>
<a class="story-title" target="_blank" href="">Qvaq: A Key to Easy Social Communication Online</a>
<a class="story-title" target="_blank" href="">5 Fictional Stories You Were Taught in History Class</a>
<a class="story-title" target="_blank" href="">Blooper Reels From The Original Star Trek Series</a>
<a class="story-title" target="_blank" href="">Top Ten Disney Properties Underrepresented in Kingdom Hearts</a>
<a class="story-title" target="_blank" href="">9 Awesome Slacker Jobs You Could Actually Have</a>
<a class="story-title" target="_blank" href="">Microsoft Xbox Live Team Says Too Gay To Play</a>


This stuff is freaking awesome. YUI3 is the only major framework that I've come across that's up and running with node.js.

I wanted to give you a heads up on a error that I just encountered. I'm using a clean install of node, npm and yui3 for node.js and I receive the following error while trying to execute the above example. I'm wondering if one of the yui3 modules has changed since this example was posted?

error: (nodejsyui3): ----------------------------------------------------------
error: (nodejsyui3): TypeError: Cannot call method 'addListener' of undefined
error: (nodejsyui3): at Object.send (/usr/local/lib/node/.npm/yui3/0.5.19/package/lib/yui3-io.js:42:32)
error: (nodejsyui3): at Function.xdr (/usr/local/lib/node/.npm/yui3-core/3.3.0/package/build/io/io-min.js:2:357)
error: (nodejsyui3): at A (/usr/local/lib/node/.npm/yui3-core/3.3.0/package/build/io/io-min.js:1:3332)
error: (nodejsyui3): at [object Object].io (/usr/local/lib/node/.npm/yui3/0.5.19/package/lib/yui3-io.js:138:16)
error: (nodejsyui3): at /usr/local/lib/node/.npm/yui3/0.5.19/package/lib/yui3-yui3.js:194:18
error: (nodejsyui3): at [object Object]._notify (/usr/local/lib/node/.npm/yui3-core/3.3.0/package/build/yui/yui-debug.js:642:17)
error: (nodejsyui3): at /usr/local/lib/node/.npm/yui3-core/3.3.0/package/build/yui/yui-debug.js:629:23
error: (nodejsyui3): at [object Object]._notify (/usr/local/lib/node/.npm/yui3-core/3.3.0/package/build/yui/yui-debug.js:642:17)
error: (nodejsyui3): at [object Object]. (/usr/local/lib/node/.npm/yui3-core/3.3.0/package/build/yui/yui-debug.js:756:27)
error: (nodejsyui3): at Object._finish (/usr/local/lib/node/.npm/yui3-core/3.3.0/package/build/loader/loader-debug.js:1632:19)
error: (nodejsyui3): ----------------------------------------------------------


If your running 0.3.7, you need to pull my latest from github and npm install it.. I haven't released a patch yet for the new HTTP Client in 0.3.7


Hi davglass,

I was wondering how i can load a local file/a string to use it as document.
I saw in this gist that you do it with fetch for remote url so I bet you have made some methods to load a string or a file can you enlight me on how to do it ?



Hi Dav,
I am getting the error when i am running the above example by using $node digg.js::

error: (nodejsyui3): Error: Cannot find module '../build/Release/contextify'
error: (nodejsyui3): at Function._resolveFilename (module.js:326:11)
error: (nodejsyui3): at Function._load (module.js:271:25)
error: (nodejsyui3): at require (module.js:355:19)
error: (nodejsyui3): at Object. (/home/abbas/.node_libraries/.npm/contextify/0.0.6/package/lib/contextify.js:2:22)
error: (nodejsyui3): at Module._compile (module.js:411:26)
error: (nodejsyui3): at Object..js (module.js:417:10)
error: (nodejsyui3): at Module.load (module.js:343:31)
error: (nodejsyui3): at Function._load (module.js:302:12)
error: (nodejsyui3): at require (module.js:355:19)
error: (nodejsyui3): at Object. (/home/abbas/.node_libraries/.npm/jsdom/0.2.9/node_modules/contextify/index.js:11:18)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.