I\'m trying to use some jquery in my project and as soon as I tried using it I came across an error in copied code and can\'t get any google help on it
var
You can't use jquery on server as it explicitly requires window
and window.document
. Try cheerio
try:
var jsdom = require("jsdom").jsdom;
var markup = '<html><body><h1 class="example">Hello World!</h1><p class="hello">Heya Big World!</body></html>';
var doc = jsdom(markup);
var window = doc.parentWindow;
var $ = require('jquery')(window)
console.log($('.example').text());
Basically you can use the jsdom module to create a DOM out of your markup and then you can use it as you would with jquery in the browser.
I had the same problem. To solve it I installed an older version of jquery:
npm install jquery@1.8.3
It used to work just fine for many months. But then they changed something and now it doesn't. I could run jquery without a window just fine and it worked perfectly on node js. But not with the latest version for some reason. Really weird.
What we are trying to do is just this:
$ = require("jquery"); $("..).find(".message").html("Hello World!");