fire_water
fire_water

Reputation: 1449

How to access a package variable from somewhere else in the application?

I have developed two Meteor packages that I have added into my Meteor application.
Each package has a log collection that I am trying to query from the Meteor Application. However, it seems I am unable to access those collections from the main application:

// pkg_1_log is defined in pkg_1 package.
pkg_1_log.find().count();
ReferenceError: Can't find variable: pkg_1_log

// pkg_2_log is defined in pkg_2 package.
pkg_2_log.find().count();
ReferenceError: Can't find variable: pkg_2_log

What do I need to tweak in order for that to work?

Upvotes: 1

Views: 30

Answers (1)

Kyll
Kyll

Reputation: 7139

To provide access to a package-scoped variable (defined without var), you need to export it:

api.export('myVar');

You can specify the target architecture in the second argument.

You may then meteor add your package to get this exported variable to the whole application but also api.use it in another package or even api.imply it. If you are unsure as to what the difference between "using" and "implying" is then you should check saimeunt's answer.

Upvotes: 2

Related Questions