14

it posible use a nodejs package inside meteor app on server side? It would be great to do that since nodejs has a large number of packages.

Pointy
  • 405,095
  • 59
  • 585
  • 614
Topicus
  • 1,394
  • 1
  • 15
  • 27
  • possible duplicate of [2013 Meteor NPM Packages](http://stackoverflow.com/questions/15583438/2013-meteor-npm-packages) – BenjaminRH Mar 05 '14 at 16:43

1 Answers1

26

Yes, it is possible. You can use an npm module in Meteor, since it's based on Node.js.

This code has worked for me fine, e.g.:

var fs = __meteor_bootstrap__.require('fs');

UPDATE: To install an npm module in a Meteor app

  1. Inside your terminal, change path to your Meteor app directory.
  2. > cd .meteor/local/build/server
  3. Install an npm module like so > npm install module_name.

 


 

Edit: for anyone visiting this post, it is outdated. As of Meteor 0.6.4, you use Npm.require instead of __meteor_bootstrap__.require:

var fs = Npm.require('fs');

Also, if you don't use standard node package, but one from npm repositories, it's better to create a dependency so that it's automatically installed every time you create a new instance of the project. To do so, create a /packages/someName/package.js file with the following line:

Npm.depends({'packageName': 'packageVersion'});
Hubert OG
  • 19,314
  • 7
  • 45
  • 73
nsmeta
  • 1,898
  • 1
  • 17
  • 14
  • Thank you very much for your answer but how could I install nodejs packages inside a meteor app? – Topicus Jul 27 '12 at 16:57
  • Sorry I should've included this information in the first place. I've now updated my answer with the relevant info. Hope it helps. :) – nsmeta Jul 27 '12 at 17:30
  • 2
    Any idea on how to make modules with transitive dependencies work? Like aws-lib for example? – Joscha Aug 16 '12 at 03:28
  • 2
    This answer is incorrect... `Npm.depends()` is [only for use in a `package.js` file](http://docs.meteor.com/#Npm-depends). Use the [meteorhacks:npm package](https://atmospherejs.com/meteorhacks/npm) to be able to use npm modules in Meteor apps. – Adam Monsen Oct 06 '14 at 22:58