With Meteor you only can use npm modules inside packages

I just want to know/understand why is this and why meteor is one thing and meteor packages is another thing.
Why i can use freely npm modules inside packages and inside meteor app i have to use this
meteor add meteorhacks:npm and still i have to code strangely with Async.runSync

1 Like

Yes you are correct. Meteor treat them differently. That’s because meteor has no built in way to define list of npm modules for the app. That’s what meteorhacks:npm does. There was some plans to integrate something like this into core. But, I didn’t hear much about it.

On the other hand. It’s very important to use Async.runSync or Meteor’s built in Meteor.wrapAsync. Reason it simple. Most of the NPM modules comes with async api either with callbacks or promises.

But, with meteor we write code in sync style. So, we need npm modules to a format where we can use with Meteor. That’s the reason for Async.runSync.

Still confused.
I can move more code from meteor app to a package right ? this way i still do it nodejs style.

still i have to code strangely with Async.runSync

Meteor runs server code in Fibers. This allows you to write your code in a synchronous style without blocking the Node.js event loop. When you use a npm package it usually uses the callback style for asynchronous code. To convert such a method to a synchronous Fiber style version, you use Meteor.wrapAsync. This is however optional. You can still use callback in Meteor server code if you want. But I would recommend to embrace the Meteor way.

Further resources:

1 Like

I’m sure Npm.require wouldn’t be too hard to add on the app level, along with meteor npm add <package-name> for the CLI. Related: I’m working on rocket:module to handle npm dependencies and to let you write code with CJS/AMD/ES6 Modules. More info here.

1 Like