Reputation: 7996
I'm trying to install the Spooky module in meteor (this one is in my public folder: app/public/node_modules).
I've read answers in this post and added the following code in server/server.js
Meteor.startup ->
path = Npm.require 'path'
fs = Npm.require 'fs'
base = path.resolve '.'
isBundle = fs.existsSync base + '/bundle'
modulePath = base + (if isBundle then '/bundle/static' else '/public') + '/node_modules'
spooky = Npm.require modulePath + '/spooky'
But when I'm running meteor I get:
Error: Cannot find module '/Users/mac/Documents/websites/app/.meteor/local/build/programs/server/public/node_modules/spooky'
Upvotes: 3
Views: 5248
Reputation: 19674
The article Akshat linked to has been updated:
cd project
meteor add meteorhacks:npm
Edit project/packages.json
:
{
"redis": "0.8.2",
"github": "0.1.8"
}
Use those npm modules:
var Github = Meteor.npmRequire('github');
var github = new Github();
github.gists.getFromUser({user: 'arunoda'}, function(err, gists) {
console.log(gists);
});
Upvotes: 0
Reputation: 75965
You need to create a smart package to use Npm modules in your app. Alternatively you can use meteor-npm.
You can't use Npm.require
on its own for non standard npm modules like spooky.
If you use meteor-npm you can install it with meteorite: mrt add npm
Then use Meteor.require("spooky")
instead, after you have added the module to your packages.json. You can have a look here for more details: http://meteorhacks.com/complete-npm-integration-for-meteor.html.
The official way to do it is to make your own smart package to wrap the npm module in. There is an example of such a package: https://github.com/avital/meteor-xml2js-npm-demo
The example uses xml2js as the npm module, but you could swap the names around so its spooky instead.
Then you can add this package into your /packages
folder (say with the name spooky
), and add it to your meteor project with meteor add spooky
.
The packages on atmosphere.meteor.com have more examples of this, they pretty much do the same thing (e.g stripe (https://atmosphere.meteor.com/package/stripe)).
Upvotes: 1