Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2015
What would you like to do?
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.


  • 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