I am new to Node.JS but very experienced with JavaScript and jQuery. I have had no problem installing jQuery via npm install jquery
, however, referencing plugins within the code is another challenge.
I have reviewed this similar StackOverflow question, and the solution appears to work but it seems to me that instantiating a "fake" browser window and injecting your jQuery plugin-based functions each time you need the plugin is possibly not the most efficient approach.
The specific plugin that is failing for me linq.js (yes, I am aware that js linq is available via npm but it is not the same as linq.js!).
NOTE: The plugin to which I am referring does not rely on any DOM elements; in my case, it simply runs JSON objects through various data functions. This is why I don't think I need to instantiate a window object.
How do I properly import and use jQuery plugins in a Node.JS application?
You don't.
You don't use jQuery on the server, ever. It has no place there, you don't have a DOM on the server and jQuery itself is a mediocre library to start with.
If you really want to use a "jQuery plugin" in node, you rewrite the plugin as a standalone module without a jQuery dependency.
As an aside, you also shouldn't need linq.js because it's an API you don't need, you already have array methods. Also your coding C# in JavaScript rather then learning JavaScript.
You also have all the array methods (map, filter, reduce, etc) so you simply do not need this. If you really want some of the sugar linq.js offers use underscore instead. (I personally recommend for ES5 over underscore)
Please use ECMAScript correctly rather then emulating C#.
it stands for "Language Integrated Querying".
-- Sure, that's the benefit of real LINQ -- it's integrated into the language. linq.js is not integrated into the language, it's just written in the language. Same with PHPLinq, linqj, and the others. That means instead of your query being composed of keywords and variables, like a normal expression, it's just a big string. Ignoring the fact that linq.js implicitly makes a bogus claim at language integration by naming itself "linq," can you give a concrete example of where it might actually be a useful abstraction - Dagg Nabbit 2012-04-08 22:49
filteredData = data.Where(function (x) { return x[target] == comparer; });
is pretty darn useful to me. As are the 'skip', 'take','distinct', 'intersect', 'groupby', and 'orderby' abstractions. These operations are abstracting away lower-level operations on JSON objects (in my case) such as binary searches, merge sorts and so on by allowing me to write them with a single line of code. What is so wrong with that - Matt Cashatt 2012-04-09 10:51
data.filter
comment. That is useful. So is it your opinion that POJS can handle, in as few lines of code as linq.js, all of the other operations I am looking for such as 'skip', 'take','distinct', 'intersect', 'groupby', and 'orderby'? Obviously I am simply looking for abstractions that make querying data expedient and clean in code. Hopefully you don't have anything against abstractions in general because I don't think I could come to agreement with that, but if I have simply missed that POJS can do all of these things natively and easily please let me know - Matt Cashatt 2012-04-09 11:06