Meteor - Best Practices


Advertisements

We already covered some of the best practices of Meteor development in the previous chapters. Following are some of the best practices to be kept in mind while using Meteor.

Directory Structure

There are no strict rules about the directory structure in Meteor apps. For more info on guidelines, check out Meteor - Structure chapter.

Use Methods

You should always use Meteor - Methodswhen working with sensitive data instead of calling insert, update, and remove directly from the client.

Data Management

Protect your data using Publish and Subscribe methods. If you want your data to be available to all clients, you can use null as the publication name instead. Publishing small chunks of data will also improve the performance of the app.

Validate Data

You should validate all data that will be stored inside collection. One of the best options is collection2 package. This package makes it easy to set the server and client side validation.

Minimize Session

The session variables are global variables and using globals is against the JavaScript best practices.

Router

There are two most popular options for Meteor routing. For smaller apps, there is Iron Router. It is automatically rerun once the data changes. For larger apps, there is Flow Router. This router gives you more freedom to optimize re-rendering of the templates at the cost of a little more boilerplate code.

Packages

Always check if the package is updated regularly before you choose to use it inside your app.

Advertisements