Where to declare global functions?

I’m a newbie and following an old (2015) tutorial from Udemy. The guy have a single todo.js file with both client and server code. He’s declaring all global stuff outside if (Meteor.isClient) and if (Meteor.isServer) tags. for example Todos = new Mongo.Collection('todos'); and same for Meteor.methods().

But i have a separate main.js file for both client and server with new project. So i’m adding same code in both files. Otherwise they wouldn’t work. What is the best way to add Meteor.methods and other global functions without repeating the code?

It’s highly recommended that you don’t use globals.

Try the official tutorials for the latest version of Meteor here:
https://www.meteor.com/tutorials/

1 Like

There is a directory structure that defines which code is loaded on client, server or both. With ES2016 you can have better control over what is loaded and when it is loaded. Check out https://guide.meteor.com/structure.html

1 Like