Last active
February 24, 2022 13:10
-
-
Save webdevian/594a9affbee2831510ae4c5d9563b35e to your computer and use it in GitHub Desktop.
Heroku Copy Environment Variable from one app to another
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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