3

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'
Community
  • 1
  • 1
Julien Le Coupanec
  • 7,742
  • 9
  • 53
  • 67
  • just install the package with -g (`npm install -g packagename`). The `public` folder is outward facing and visible to everyone. You don't want that. Plus meteor/node doesn't it find it there. – Christian Fritz Feb 04 '14 at 23:30

2 Answers2

1

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

Tarang
  • 75,157
  • 39
  • 215
  • 276
0

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);
});
Community
  • 1
  • 1
Cees Timmerman
  • 17,623
  • 11
  • 91
  • 124