Search code examples
node.jsherokuheroku-cli

How to manage DEV and PROD deployment on Heroku with Node.js


I am using Heroku with Node.js and Git as a version manager.

As soon as I want to modify my production code I create a new branch.

I would like to be able to deploy this branch in a DEV mode (with different configuration files, with different DB address for instance) and when I merge be able to deploy in a PROD mode.

Any idea how I could manage this in an easy way ?


Solution

  • Here is one possible solution:

    From the SO.org tag I suppose you use Node.js. For config handling, there is great library https://github.com/lorenwest/node-config, which makes multi env config handling easy. Here are possible envs config/test.js, config/development.js, config/staging.js. To switch between environments change the env variable NODE_ENV=staging. Do keep your secrets out of the version control you could set the NODE_CONFIG variable to override the default settings https://github.com/lorenwest/node-config/wiki/Environment-Variables#node_config.

    Heroku has made deployment really easy with pipelines, suggest reading more here https://devcenter.heroku.com/articles/pipelines#multiple-apps-in-a-pipeline-stage. Create a new pipeline with two stages: staging and production. Deploy your app to staging manually or through some CI tool(CircleCI, Jenkins etc). When you are ready to move to production you don't need to go through all the build/install process but just promote the staging build to production.