Trying to write NPM module for Meteor 1.3

Hi,

I’m trying to make NPM package for Meteor 1.3. Everything is OK except one small issue: how to execute code server side from the package?

If I simply add:

console.log(Meteor.isServer); 

It executes automatically when app is started at client (properly returning false), but it doesn’t execute automatically at server. Of course, I can create function and call it from my applications server code, but I want code to execute automatically when server starts - for example, I want to execute Meteor.publish in a package.

How to do that?

Thanks!

If there is existing npm module with similar functionality - I’ll appreciate the link. Thanks!

OMG, It was obvious - If I simply import any exported thing from the package at the server, then code executes.

But, it still doesn’t look as proper solution:

NPM package:

export const Dummy = {};

if(Meteor.isServer) {
  Meteor.publish("something", function() {
    console.log("Yahoooo! Publish executed!");
    return this.ready();
  });
}

My app server.js

import {Dummy} from "my-npm-package"; 

And publish executes!

Now… how to execute the same thing without importing “Dummy” thing?

Thanks in advance! :slight_smile:

2 Likes

You can just do import 'my-npm-package' to avoid the random export. but I am unsure if you are saying that meteor is doing some weird stuff in trying to figure ou tif should automatically run code or not.