2013 Meteor NPM Packages

Update This solution describes how to leverage the new Npm system in Meteor.




What is the current method for using NPM packages in Meteor?

As of March 22, 2013, there is no official documentation on this issue.

There are several questions about this, especially this one , however the solution seems outdated: the engine branch no longer exists, and I could not find anything on Npm.require in Meteor.

Another solution posted here provides installation instructions for the .meteor/ folders. Since I am installing on Heroku, this does not seem to be the right solution, since buildpack uses the meteor bundle to meteor bundle program before running it. Thus, temporary creation folders do not look like a valid option.

What happened to Npm in a meteor? What is the last way to use Npm packages?

In a related note, I'm trying to use the Amazon SDK (for s3) - would it be better to just pack it as a Meteorite package?

+21
npm meteor
Mar 23 '13 at 4:43
source share
5 answers

Arunoda has created the NPM Atmosphere package , which allows you to use any NPM module you are used to. It is very simple.

First mrt add npm .

You can also install the package using the meteor-npm command from npm install -g meteor-npm .

Then create the packages.json file in the project root with the names and versions of the packages:

 { "foobar": "0.3.5", "loremipsum": "2.1.4" } 

Finally, use them with Meteor.require , for example: var FooBar = Meteor.require('foobar');

+22
Jun 18 '13 at 22:26
source share

The current way to use NPM in Meteor

  • Replace x below with NPM
  • Put the file paths below in / meteor -project-root / packages / x /
  • Meteor add x
  • To use it, just call X in your code (X.function ())

x.js --------

 X = Npm.require('x'); 

package.js --------

 Package.describe({ summary: "Meteor smart package for x node.js package" }); Npm.depends({ "x": "0.1.1" }); Package.on_use(function (api) { api.add_files("x.js", ["client", "server"]); }); 

Note. Some packages will only work on the client or server, if you have problems, try to include only the side where you intend to use it.

+9
May 30 '13 at 6:07
source share

I use the fantastic " browserify ", which works like a charm. This is an alternative to using the Arunda NPM Atmosphere package or using Npm.require with package.js , which may have some advantages:

  • My code may use the plain old "require" instead of Npm.require or Meteor.require. Obviously, this is not a huge deal, but if I want to use this code outside of Meteor, it's nice to feel that it is not dependent on Meteor.
  • I don’t have to worry about whether Meteor will once again change the way he thinks about integrating into Npm again.
  • This allows me to use the local version to develop my own npm modules using the npm link.

Here's how it works:

  • I am creating a separate project for npm dependencies in a hidden .npm folder
  • I use a browser to create a bundle.js package that will be loaded by a meteorite
  • I use gunt watch to make sure bundle.js is updated every time I install a new npm package

Here is my directory structure:

 my_meteor_project/ lib/ bundle.js .npm/ node_modules README.md Gruntfile.js entrypoint.js package.json 

Here is an example entrypoint.js (unfortunately, I need to use global variables so that assert, url and _ are available in Meteor code)

 assert = require('assert'); url = require("url"); _ = require('underscore'); 

Here's the grunt file:

 module.exports = function(grunt) { grunt.initConfig({ watch: { build: { files: ['./entrypoint.js', './package.json'], tasks: ['browserify2'], options: { } } }, browserify2: { compile: { entry: './entrypoint.js', compile: '../lib/bundle.js' } }, }); grunt.loadNpmTasks('grunt-browserify2'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.registerTask('build', ['browserify2']); }; 

Then I use the grunt clock to view changes in entry.js or new NPM installations

 $ cd .npm $ grunt watch:build & [2] 44617 $ Running "watch:build" (watch) task Waiting... 

And if I installed the npm module or changed entrypoint.js, bundle.js will update:

 $ npm install url -save npm http GET https://registry.npmjs.org/punycode npm http GET https://registry.npmjs.org/querystring npm http 304 https://registry.npmjs.org/punycode npm http 304 https://registry.npmjs.org/querystring url@0.7.9 node_modules/url β”œβ”€β”€ querystring@0.1.0 └── punycode@1.0.0 $ OK >> File "package.json" changed. Running "browserify2:compile" (browserify2) task File written to: ../lib/bundle.js Done, without errors. Completed in 1.256s at Thu Jul 11 2013 11:36:22 GMT-0600 (MDT) - Waiting... 
+3
Jul 11 '13 at 17:48
source share

You can use https://atmospherejs.com/meteorhacks/npm

 meteor add meteorhacks:npm 

And then you can customize the package.json file:

 { "redis": "0.8.2", "github": "0.1.8" } 

And use these packages:

 var GithubApi = Meteor.npmRequire('github'); 
+1
Jul 09 '15 at 7:24
source share

when you use a meteorite, when you install the node module in .meteor/local/build/server/ , which you actually install on

 ~/.meteorite/meteors/meteor/meteor/f07715dc70de16a7aab84e56ab0c6cbd9c1f9dc6/dev_bundle/lib/node_modules 

when you use mrt bundle to create your deployment package, additional packages are also included.

I have not tried this on Heroku, but I have verified that the node module is being packaged using the mrt package.

-one
Mar 24 '13 at 19:16
source share



All Articles