Search code examples
javascriptmeteormeteor-blaze

How to check if a Meteor package is currently installed?


I need to check if the package my-package:notification is installed in my app.

Only then another template is used (which is part of this package).

Something like this:

<template name="example">
    {{#if hasNotificationPackage}}
        {{>notification}}
    {{/if}}
</template>

How do I do that?


Solution

  • Meteor provides a global object called Package that contains all of the Meteor package exports.

    Therefore, you can use something like

    Template.example.helpers({
      hasNotificationPackage() {
        return (typeof Package['my-package:notification'] === 'object');
      }
    });
    

    I am not sure that depending on the availability of a package this way is something that should be used often, especially in production.