Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
148 views
in Technique[技术] by (71.8m points)

javascript - it possible use a nodejs package inside meteor app?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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'});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...