Is it possible to use jQuery selectors/dom manipulation server-side using node.js
?
views:
4754answers:
6Not that I know of. The DOM is a client side thing (jQuery doesn't parse the HTML, but the DOM).
Here are some current Node.js projects:
http://wiki.github.com/ry/node
And SimonW's djangode is pretty damn cool...
An alternative is to use Underscore.js. It should provide what you might of wanted server-side from JQuery.
No. It's going to be quite a big effort to port a browser environment to node.
Another approach, that I'm currently investigating for unit testing, is to create "Mock" version of jQuery that provides callbacks whenever a selector is called.
This way you could unit test your jQuery plugins without actually having a DOM. You'll still have to test in real browsers to see if your code works in the wild, but if you discover browser specific issues, you can easily "mock" those in your unit tests as well.
I'll push something to github.com/felixge once it's ready to show.
Since it is now possible to run YUI on Node.js, perhaps jQuery can be ported to.
I believe the answer to this is now yes.
http://github.com/tmpvar/jsdom/blob/master/example/jquery/run.js
var navigator = { userAgent: "node-js" };
var jQuery = require("./node-jquery").jQueryInit(window, navigator);
Using this library http://github.com/tmpvar/jsdom you now can. Just look at their jquery example in the examples directory.