I am trying to run this script below via the command line
var argv = require('optimist').argv,
$ = require('jquery'),
fs = require('fs');
var file = argv._[0];
var html = fs.readFileSync(file, 'UTF-8');
$(html).find('p').each(function(index) {
var content = $(this).html();
console.log('Paragraph ' + (index + 1) + ': ' + content);
}); //script.js
The command is $ node script.js page.html
where page.html
is the argument
The error I get is:
./node_modules/jquery/dist/jquery.js:29
throw new Error( "jQuery requires a window with a document" );
Error: jQuery requires a window with a document
at module.exports (./node_modules/jquery/dist/jquery.js:29:12)
...
I am using jquery-2.1.3. I know that this used to work, once upon a time, but it looks like something has changed.
Also I did follow the instructions at http://rkulla.blogspot.com/2014/04/using-browserify-with-jquery-backbonejs.html but I am still getting the same error.
Any help to fix this error would be greatly appreciated. Thank you very much!