Skip to content

Instantly share code, notes, and snippets.

@thanpolas
Last active August 29, 2015 14:02
Show Gist options
  • Save thanpolas/5bcb42e0ae1f34e6dc56 to your computer and use it in GitHub Desktop.
Save thanpolas/5bcb42e0ae1f34e6dc56 to your computer and use it in GitHub Desktop.
Heroku Environment mass export

Exporting sensitive data to Heroku's Environment

This script is ment to work with the node-config package, it will export whatever configuration data you set on the herokuOverride Object, as a JSON serialized string, onto the NODE_CONFIG environment variable on Heroku.

This results in the config package to use those values instead, thus enabling you to keep sensitive data out of your tracked files.

Usage

  • Add env.js to your .gitignore file
  • Edit it as per your needs
  • Simply invoke using the node interpreter: node ./env
/**
* @fileOverview Export passwords and sensitive shit to Heroku environment variables.
*/
var exec = require('child_process').exec;
var local = false;
var herokuOverride = {
cookies: {
session: {
secret: 'xxx',
},
},
crypto: {
salt: 'xxx',
},
mongo: {
user: 'user',
pass: 'pass',
database: 'dbname',
hostname: 'where.the.fu:6666',
uri: 'mongodb://user:pass@where.the.fu:6666/dbname',
},
};
var jsoned = JSON.stringify(herokuOverride);
var re = new RegExp('"', 'g');
var cmd;
if (local) {
cmd = 'export NODE_CONFIG="';
cmd += jsoned.replace(re, '\\"');
cmd += '"';
} else {
cmd = 'heroku config:set NODE_CONFIG="';
cmd += jsoned.replace(re, '\\"');
// cmd += '" --app your-app';
}
console.log('Executing:\n', cmd);
exec(cmd, null, function (err, stdout, stderr) {
console.log('Finished executing:', err, stdout, stderr);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment