cannot find module ‘jsdom’

An error I came across when trying to install jsdom npm package on my windows machine. “cannot find module ‘jsdom’.

An error I came across when trying to install jsdom npm package on my windows machine. "cannot find module 'jsdom'.

Solutions:

1. Follow instructions on this blog post to get jsdom working on windows.
http://www.steveworkman.com/node-js/2012/installing-jsdom-on-windows/

2. Use an alternative (lighter) package called Cheerio.

Notes:

Something I ran into was this error when using cheerio.

“cheerio $ is not defined”

"cheerio $ is not defined"

It requires the var statement pre variables, probably a scope thing.

Node.js code snippet.

var options = {
    url: url,
    headers: {
        'User-Agent': 'my-app'
    },
    timeout: 30000
  };

request.get( options, function( err, res, html ) {

  //catch errors
  if ( err || res.statusCode !== 200 ) {
    console.log( 'error while trying to get page content.' );
    console.log( err );
    return '';
  }
  console.log( html );

  try {
    //https://github.com/cheeriojs/cheerio
    var $ = cheerio.load( html );
    var $body = $( 'body' );  //<-- $ is not defined
    console.log( $body );
  }
  catch(err) {
    console.log( 'error getting img '+err );
    return '';
  }

});

refs:
https://github.com/cheeriojs/cheerio/issues/454
https://github.com/asciidisco/grunt-requirejs/issues/5