Search code examples
herokuheroku-cli

Set enviroment variables in Heroku from .env file


I'm developing a Node application using Docker and docker-compose, which all have awesome ways to import multiple environment variables from a .env file.

Just wondering if there's a shortcut for updating a Heroku deployment's env vars instead of typing them out.

I've noticed there's no --env-file option on the official docs: https://devcenter.heroku.com/articles/config-vars


Solution

  • Using some xargs magic

    cat .env.prod | xargs heroku config:set
    
    # Output:
    # API_PORT:       3000
    # API_KEY_1:      ab-cd
    # DB_PORT:        6379
    # REDISCLOUD_URL: xxx
    

    Happily sets multiple args from a local .env file