Complete NPM integration for Meteor
See MeteorHacks article on Complete NPM integration for Meteor
meteorhacks:npm
package instead.
If your Meteor version is >= 0.9.0, Please use Adding NPM support to your app
Via Meteorite
mrt add npm
If you are working on multiple meteor projects at the sametime or using different versions, try to use following method instead using it with meteorite
Via NPM
npm install -g meteor-npm #single time operation meteor-npm #type inside your project
This creates a package named npm
inside your project and it has no link with meteorite. It is also included in your git.
With this, you can use npm in multiple meteor projects without a problem, regardless of their versions.
Create packages.json file for listing dependencies.
If you need to install an npm module from a specific commit, use the syntax:
Example on using npm module inside a Meteor method
if MeteorisClient { Meteor; } if MeteorisServer Meteor;
API
Available in the Server Side only
Meteor.require(npmModuleName)
This method loads NPM modules you've specified in the packages.json
file.
var Github = Meteor;
Async Utilities
Available in the Server Side only
Meteor APIs are executed synchronously. Most of the NodeJS modules works asynchronously. So we need a way to bride the gap. Async Utilities comes to rescue you.
Async.runSync(function)
Async.runSync()
pause the execution until you invoke done()
callback as shown below.
var response = Async; console; // 1001
done()
callback takes 2 arguments. error
and the result
object. You can get them as the return value of the Async.runSync()
as shown as response in the above example.
return value is an object and it has 2 fields. error
and result
.
Meteor.sync(function)
Same as Async.runSync
but deprecated.
Async.wrap(function)
Wrap an asynchronous function and allow it to be run inside Meteor without callbacks.
//declare a simple async function { ;} //wrappingvar wrappedDelayedMessage = Async; //usageMeteor;
If the callback has a result, it will be returned from the wrapped function. If there is an error, it will be thrown.
Async.wrap(function)
is very similar toMeteor._wrapAsync
.
Async.wrap(object, functionName)
Very similar to Async.wrap(function)
,
but this API can be used to wrap an instance method of an object.
var github = version: "3.0.0"; //wrapping github.user.getFromvar wrappedGetFrom = Async;
Async.wrap(object, functionNameList)
Very similar to Async.wrap(object, functionName)
,
but this API can be used to wrap multiple instance methods of an object.
var github = version: "3.0.0"; //wrapping github.user.getFrom and github.user.getEmailsvar wrappedGithubUser = Async; //usagevar profile = wrappedGithubUser;var emails = wrappedGithubUser;