I am using jQuery with jsdom in my node.js. application
Also, I want to use jQuery plugins (like jQuery.diff), but I can't find how to do this. Is there a way out?
Create a script tag in your document to load a script into it. Example:
createWindow = function(fn) { var window = jsdom.jsdom().createWindow(), script = window.document.createElement('script'); jsdom.jQueryify(window, function() { script.src = 'file://' + __dirname + '/some.library.js'; script.onload = function() { if (this.readyState === 'complete') { fn(window); } } }); } createWindow(function(window) { // Do your jQuery stuff: window.$('body').hide(); });
Source: http://blog.davidpadbury.com/2010/10/03/using-nodejs-to-render-js-charts-on-server/
I have a library I'm working on, which is the jquery port for node - bit.ly/node -jquery
The goal is to make var $ = require('node-jquery') and use jquery libraries or functions as normal
$ = require('node-jquery')