9

Background

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.

Question

How do I properly import and use jQuery plugins in a Node.JS application?

4
  • 2
    Thanks for sharing linq.js, looks awesome. Since no one did it, I took the time to package it for node and publish it to npm (the changes were trivial). github.com/mihaifm/linq It currently works as a standalone library and not as a plugin, so I don't know how to answer your question :) Commented Apr 7, 2012 at 12:23
  • 3
    jQuery is not something that should run on node. You don't do this. Ever. Just because you can take 10 hits of acid and run naked through the streets doesn't mean you should; just because you can run JavaScript on the server doesn't mean you should try and put jQuery there. Commented Apr 8, 2012 at 23:00
  • 4
    @Incognito--yes, but why??? You are obviously good at making a cliche and chic statement about how not to use a technology but your comment isn't helpful. Tell us why you say this and I might come over to your way of thinking. I will grant you that jQuery isn't meant for node, but it DOES have hundreds of useful plugins. I think we should start a conversation about how we can adapt and improve upon those plugins and make node even better. Commented Apr 9, 2012 at 3:29
  • 1
    @mihai--Thanks for packaging linq.js. Can you please answer this question with the steps for packaging (in general) such a plugin for node and then I will gladly select your answer as the winner. Commented Apr 9, 2012 at 3:35

2 Answers 2

-1

You can't do this. JQuery manipulates DOM on the client-side, which means that it has no business on the server-side where NodeJs runs.

Sign up to request clarification or add additional context in comments.

Comments

-4

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#.

15 Comments

All due respect, your answer completely misses the mark and indicates that you didn't read the question in it's entirety. A couple of errors in your statement reflect simple misconceptions. For example, linq.js has nothing to do with SQL nor the DOM per se. Linq is one of the best technologies to come out of Microsoft IMO and it stands for "Language Integrated Querying". Linq allows, for example, Lambda expressions against runtime variables. In the case of linq.js, it can mean DOM elements or just JSON objects. You may consider opening your mind a bit to new possibilities.
@MatthewPatrickCashatt all due respect but linq.js is a joke, don't use it
I can't help agreeing with @Raynos on the point that using jQuery on the server is sacrilege, particularly if you just want a plugin. He's just not argued the point very clearly. And on the point of linq.js, passing string arguments into methods like that is mighty ugly. It's a hack promoted by familiarity that would aid you if you were porting code directly, but it goes against the grain of js somewhat. But opinions aside, if you need linq.js then use the jQuery-less version at least, which has been packaged
@MatthewPatrickCashatt 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?
Haters gonna hate but coming from Microsoft it should set off all alarm bells.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.