DEV Community

Filipe Névola
Filipe Névola

Posted on

Understanding Meteor's Settings File

Understanding configuration files is essential in the world of Javascript programming and Meteor. You see, typically, most frameworks lack a standard configuration file. Instead, developers use environment variables, which they retrieve when needed. However, Meteor, about ten years ago, chose a different path and decided to introduce a settings file, which essentially transforms into an environment variable in most places.

The Basics of Meteor's Configuration

This unique feature of Meteor allows you to store all configurations in a single JSON. Meteor takes this JSON and transforms it into an environment variable. But there's no magic trick here. Meteor, on its own, loads this JSON into a variable termed Meteor.settings. So, how does it work? Let's explore.

JSON relies on key-value pairs. In the Meteor's settings file, there's a key named public. If you place any configurations within the public key, Meteor automatically forwards it to the client. As a result, you can effortlessly access whatever is public from the client side.

Understanding Public and Private Segments

However, anything that doesn't fall within this public key at the primary level does not reach the client side and remains server-side only. This unique feature is the only "magic" that Meteor performs.

The utility of this settings file from Meteor is that it can also be used to pass configurations to the client side. Usually, passing configurations to the client side warrants extra work since no environmental variables are available on the client side (considering the client side is really the user's browser, and you can't control the user's environment variables).

Think of the settings file as a configuration document that you can use to pass configurations to both the server and the client. However, it's important to distinguish what is public (and therefore accessible client-side) and what should stay only on the server.

How to Provide the Settings File to Meteor

It's crucial to provide the settings file correctly to Meteor for effective functioning. To pass these settings to the Meteor application, you must use the --settings parameter. When running your Meteor app, include the settings file as follows:

meteor --settings settings.json
Enter fullscreen mode Exit fullscreen mode

In this command, settings.json is the file containing your settings. Notably, the --settings property helps Meteor recognize this file and load the configurations correctly into Meteor.settings, making the configurations available to your application. This way, you can manage server and client configurations within your Meteor application by utilizing the settings file.

Conclusion

Thus, the settings feature of Meteor simplifies a lot of tasks and provides additional ease of use for developers. The settings file is a handy tool, especially for simplifying and managing configurations effectively and efficiently.

Want to try Meteor on the server? Try zCloud. See how to use Meteor settings in zCloud here.

Top comments (0)