sites
sites

Reputation: 21795

Require jQuery in Meteor server side

I saw:

https://groups.google.com/forum/#!topic/meteor-core/ZlPPrH7SqrE

http://guaka.org/guaka-jquery-meteor-server-side-try-var-meteor-bootstrap-requirejquery-javascript-0

Server-side jquery

How can one parse HTML server-side with Meteor?

And I have not figured out a way to include jQuery in Meteor server side. Anyone knows?

I tried:

Npm.require('jquery')
Npm.require('jQuery')

But package is not found:

# Npm.require('jquery')
►[Error][Error: Cannot find module 'jquery']

Upvotes: 2

Views: 2742

Answers (2)

sites
sites

Reputation: 21795

For Meteor 1.0

Create .meteor/package.json with:

{
  "dependencies":{
    "jquery": "*"
  }
}

Then cd .meteor and run npm install to install jquery in .meteor/node_modules.

Then you can use in server Npm.require('jquery').

And add node_modules in .meteor/.gitignore so you don't push dependencies that will be installed with npm install.

There is a problem though, npm does not keep track versions of installed packages. To do that, run npm shrinkwrap in .meteor, that way, when another developer run npm install in another machine will get the same version you installed.

Upvotes: 0

Marek Takac
Marek Takac

Reputation: 3048

Try using this package https://github.com/meteorhacks/npm

  1. Run $: meteor add meteorhacks:npm
  2. in packages.json specify npm package and it's version { "jquery": 2.1.1 }
  3. Require jQuery Meteor.npmRequire("jquery");
  4. fire up your server $: meteor

Upvotes: 2

Related Questions