Skip to content
andrewshell edited this page Jan 3, 2015 · 5 revisions

by Andrew Shell on Dec 21, 2014

Update Jan 3, 2015

I no longer think that a config file is required. On the server-snacks list it was recommended to use node-foreman and a .env file. This then works exactly like a config file would, only it's loaded into the env vars for that particular app. No overlap.

Summary

  1. If someone wants to host multiple apps on a single VPS then they may not want to rely on global environment variables in order to configure their apps.

  2. We don't want to replace environment variables, because they are the way to configure Heroku apps. So the config file would have to be optional.

Pros

  1. Self documenting. It is obvious what the config variables are available to change. Comments in the file can explain what valid values would be

  2. If you're running different apps on the same server you can isolate what options they use. For instance both storage and river4 rely on the environment variables s3Path, PORT, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY

Cons

  1. Extra code to maintain

  2. Potential for credentials getting published if user isn't careful (backing up code or committing to forked repo for example)

  3. Unsure of real world demand for this feature

Implementation

// config.js

var config  =  {};

config.PORT = '8088';

module.exports = config;
// storage.js

try {
    // Try to load the config file
    var config = require('./config.js');
    }
catch (e) {
    // If it didn't exist set a default
    var config = {};
    console.log('No config file');
    }

// If config.PORT exists use it, otherwise go with the env var
var myPort = config.PORT | process.env.PORT;

Comments

Please edit this document and include your comments/questions. Ideally number them and mention who you are in case we have multiple commenters.

  1. Andrew: This is a sample comment. :-)
Clone this wiki locally