I'm posting here at
David Glasser's suggestion in ticket #1116, echoing the voices of several users who have asked for
Meteor.settings to be readable from a file in addition to (or even instead of) an environment variable. The main reasons for this request are:
- Environment variables are almost always single-line, and the ecosystem has evolved in that direction. Meteor.settings consists of multiple lines of JSON.
- Setting environment variables is platform-specific, and may require different escaping of special characters during manipulation from launch scripts (since the user is practically forced to do so, e.g. export METEOR_SETTINGS=$(cat whatever.json)), while a JSON file would be cross-platform and a single source of truth, without the need for pre-processing.
- In development mode (meteor run), --settings takes a file. For consistency, this could happen in production as well.
- Debugging environment variables is significantly more painful than debugging JSON.
- Some platforms may limit the size of environment variables, while the JSON can grow quite large.
- Storing settings in a file would enable file watching and automatic restart of the app when settings change (e.g. via forever, pm2, node-supervisor)
- pm2, a more powerful alternative to forever, takes app settings in a JSON file. That file can include environment variables for the app. However, passing Meteor's JSON settings as an environment variable inside the pm2 JSON is an exercise in frustration: a JSON encoded as a value string inside another JSON. JSON doesn't support multi-line values, double quotes need to be escaped etc.
- Users have been dissatisfied with and confused by the current approach.
At StockBase, we found it much more convenient to use the Assets API for now:
App.settings = EJSON.parse(Assets.getText('production.json'));
Of course, that doesn't push the public key to the client, so a real fix would be highly desirable.