Skip to content

Instantly share code, notes, and snippets.

@webdevian
Last active February 24, 2022 13:10
Show Gist options
  • Select an option

  • Save webdevian/594a9affbee2831510ae4c5d9563b35e to your computer and use it in GitHub Desktop.

Select an option

Save webdevian/594a9affbee2831510ae4c5d9563b35e to your computer and use it in GitHub Desktop.
Heroku Copy Environment Variable from one app to another
// Usage: node copy-heroku-env.js sourceAppName targetAppName
// Requires heroku cli to be installed - https://devcenter.heroku.com/articles/heroku-cli#install-the-heroku-cli
const { execSync } = require('child_process');
const args = process.argv;
const source = process.argv[process.argv.length - 2];
const target = process.argv[process.argv.length - 1];
console.log(source, target);
const configGet = execSync(`heroku config --app ${source} -j`);
try {
const config = JSON.parse(configGet.toString());
const set = Object.keys(config).map((key) => {
const value = config[key];
return `"${key}=${value}"`;
}).join(' ');
execSync(`heroku config:set ${set} --app "${target}"`, {stdio: 'inherit'})
console.info('Finished');
} catch (e) {
console.error(e)
console.info(configGet.toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment