Meteor - Settings / Configurations / Environment Variables

meteor

https://themeteorchef.com/snippets/making-use-of-settings-json/ - done reading
http://joshowens.me/environment-settings-and-security-with-meteor-js/
https://medium.com/@SamCorcos/up-and-running-with-meteor-settings-settings-json-3090d4c259ea#.lo403jauw
http://stackoverflow.com/questions/20918293/passing-in-config-file-for-the-production-instance-of-my-meteor-app

What is the purpose of the Meteor.settings object?

Meteor can take a JSON file and expose its content via the Meteor.settings object. That means you can use code like Meteor.settings.oauth.twitter.apikey. Example of such JSON file:

{
  oauth: {
    twitter: {
      'apikey': '...',
      'secret': '...'
    }
  },
  public: {
    'version': 'v1'
  }
}

Does Meteor use the settings file by default?

No. The settings file mst be specified on the command line using the --settings parameter:

meteor run --settings settings.json

Alternatively, you can store the JSON configuration object in an environment variable called Meteor.settings.

How can we expose some settings to the browser but hide other settings from the browser?

The configuration file isn't available on the client, but you can access all configuration settings stored inside a public field by using Meteor.settings.public. Any content that is stored outside the public field won't be accessible on the client and can be safely used for sensitive configuration settings.

How can we use the same settings file for all the environment?

Meteor does not support this. You can use a different settings file for each environment.

How can we access the settings in settings.json file on the server?

Meteor expose these settings via the Meteor.settings object. That means you can use code like Meteor.settings.oauth.twitter.apikey.

{
  oauth: {
    twitter: {
      'apikey': '...',
      'secret': '...'
    }
  },
  public: {
    'version': 'v1'
  }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License