Karl.S
Karl.S

Reputation: 2402

Where to declare config in Meteor server side code

I would like to know what is the best practice to declare configuration for packages on server side, I see two options but I don't know which of these one I should rely on.

Directly in the script :

CustomPackage.config({});

In a Meteor.startup() method :

Meteor.startup(function() {
    CustomPackage.config({});
});

Upvotes: 0

Views: 115

Answers (1)

Zeev G
Zeev G

Reputation: 2211

Both ways are correct. It all depends if your config needs to be set after the application has fully started or not.

I would wrap things that depend of existing data like :

if (Meteor.isServer) {
  Meteor.startup(function () {
    if (Rooms.find().count() === 0) {
      Rooms.insert({name: "Initial room"});
    }
  });
}

in your cause you don't have to wrap the config

from meteor docs:

It's good practice to wrap all code that isn't inside template events, template helpers, Meteor.methods, Meteor.publish, or Meteor.subscribe in Meteor.startup so that your application code isn't executed before the environment is ready.

http://docs.meteor.com/#/basic/Meteor-isServer

Upvotes: 1

Related Questions