Loading JQuery module in Node.js for testing purposes

135 views
Skip to first unread message

Sivakumar Mallaiyasamy

unread,
Mar 23, 2016, 12:05:37 PM3/23/16
to jsdom
Hi All,

I installed the following jquery and jsdom node modules and trying to load JQuery module for testing purposes. 

npm install jquery
npm install jsdom.

After installing these two modules, I have added the following code to load JQuery.

var $ = null;

require("jsdom").env("", function(err, window) {
console.log ('Begin');

if (err) {
console.log ('There was an error');
console.error(err);
return;
}
console.log ('Initializing Jquery');
 
$ = require("jquery")(window);
});

console.log ('The jquery object is ::' + $);


Output::

When I run the above code, the JQuery object is not initialized. What do I need to do load JQuery module in nodejs?

The jquery object is ::null

I am using the following versions:
  "name": "jsdom",
  "version": "8.1.0",

  "name": "jquery",
  "version": "2.2.1",

Thanks,
Sivakumar



Domenic Denicola

unread,
Mar 23, 2016, 12:06:58 PM3/23/16
to js...@googlegroups.com

Put your console.log inside the callback (i.e. before the `));`)

 

--
You received this message because you are subscribed to the Google Groups "jsdom" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsdom+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages