我想通过命令行运行下面这个脚本使用与无浏览器的jQuery的node.js通过命令行
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
的命令是$ node script.js page.html
其中page.html
是参数
我得到的错误是:
./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)
...
我正在使用jquery-2.1.3。我知道这曾经是一次工作,但看起来事情已经改变了。
此外,我也按照http://rkulla.blogspot.com/2014/04/using-browserify-with-jquery-backbonejs.html的指示,但我仍然得到相同的错误。
任何帮助解决这个错误将不胜感激。非常感谢你!