[[Node.js]] -[[Node.jsで設定ファイルを読み込む - Qiita>http://qiita.com/_daisuke/items/0d3a76a1290f08f4fea5]] -[[nodejsで環境によってconfigを使い分ける - Qiita>http://qiita.com/pman-taichi/items/be1060bdee3bbad78e5a]] -https://github.com/lorenwest/node-config ** 設定ファイルを jsonやyamlで記述する。 [#caae6f4a] $ npm install config yaml $ cat config/default.yaml adb: mac_address:'xx:xx:xx:xx:xx:xx' bot_url: '/xxxxxxxxx/xxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxx' $ cat index.js var config = require ('config'); var adb = config.adb; console.log(adb); console.log(adb.mac_address); console.log(adb.bot_url); jsonの場合は $ cat config/default.json { "adb": { "mac_address": "xx:xx:xx:xx:xx:xx", "bot_url": "/xxxxxxxxx/xxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxx" } } でおなじ設定値が得られる。 この設定情報は、環境設定で渡すことも可能で、 $ export NODE_CONFIG='{"adb":{...上記のJSONを改行なくしたモノ..}' ってやればOK。実行時に設定を渡したいばあいなど。