Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load NPM package in Meteor 1.0?

With the official launch of Meteor, is there a solid way to use NPM packages? I'm trying to use embed.ly but I don't see any straightforward way to do so.

Also, as a meteor novice, how do I include packages in my files? I don't see any 'require' or 'exports' functions.

Thanks!

like image 843
kaid Avatar asked Oct 30 '14 18:10

kaid


People also ask

How do I use npm on Meteor JS?

To use an npm package from a file in your application you import the name of the package: import moment from 'moment'; // this is equivalent to the standard node require: const moment = require('moment'); This imports the default export from the package into the symbol moment .

How do I use Meteor packages?

To use an Atmosphere Package in your app you can import it with the meteor/ prefix: import { Mongo } from "meteor/mongo"; Typically a package will export one or more symbols, which you'll need to reference with the destructuring syntax. You can find these exported symbols by either looking in that package's package.

What is Meteor in npm?

Meteor is a full-stack JavaScript platform for developing modern web and mobile applications. Meteor includes a key set of technologies for building connected-client reactive applications, a build tool, and a curated set of packages from the Node. js and general JavaScript community.


2 Answers

In the new "localmarket" example, they include a npm package in the package directory like this:

Request = Meteor.wrapAsync(Npm.require('request'));

and in the package.js file:

Package.describe({
  summary: "Wraps the request module from Npm in a fiber.",
  version: '0.0.0'
});

Npm.depends({request: "2.33.0"});

Package.on_use(function (api) {
  api.add_files('request-server.js', 'server');
  api.export('Request');
});
like image 170
Francis Avatar answered Oct 19 '22 06:10

Francis


You can install meteorhacks:npm

meteor add meteorhacks:npm
meteor

Meteor will then stop. You can then edit the new package.json file

{
    "request" : "2.33.0"
}

Then when you start Meteor it will install the npm modules for you.

Usage would as follows (use Meteor.npmRequire instead of require)

request = Meteor.npmRequire("request");
like image 31
Tarang Avatar answered Oct 19 '22 07:10

Tarang