Last Updated: February 25, 2016
·
909
· arunoda

Complete NPM integration for Meteor

Npm support for Meteor comes to the light from version 0.6.0. But it gives complete NPM access to packages only. If you need to use npm modules like redis, aws-sdk, colors, winston in your app, you are out of luck.

Of course, you can wrap npm modules in a package or use if it is available on atmosphere, but that's kind a hard.

Here comes the solution

Install npm package from atmosphere

mrt add npm

Create packages.json file

Then create packages.json file on your project root.

Note that, it is packages.json, not package.json

Now define npm packages you want, with the absolute package versions as shown below.

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

adding or editing packages.json file does not reload meteor. So make sure to reload meteor manually after you change it.

Let's use a npm module

Normally you are loading core npm modules using Npm.require(), But in order to load modules from your packages.json you need to use Meteor.require()

Let's get some gists using the github npm module.

var Github = Meteor.require('github');
var github = new Github();

github.gists.getFromUser({user: 'arunoda'}, function(err, gists) {
  console.log(gists);
});

Read my full article on Complete NPM Integration for Meteor