Deploy Koop app to Heroku

Heroku is a cloud platform as a service (PaaS) supporting multiple languages including Node.js. Its fully managed service and pay-as-you-go pricing model are particularly useful for testing and running Koop apps.

In this section, we show how to deploy a Koop app to Heroku using the Heroku CLI. The following guideline is based on a Koop app generated by the Koop CLI (like this) but should be applicable to all Koop apps.

Preparation

The deployment needs Git and Heroku CLI. Please read the documentation for details.

Setup

Before deploying the app, you need to specify the Node.js version and the server port for the Heroku dynos.

The Node.js version number can be added to the package.json in your app root directory.

{
  "engines": {
    "node": "12.x"
  }
}

Heroku dyno uses a dynamic port per machine and specifies it in the environment variable. You can update the src/index.js to use the provided port number.

// This is the original code at line 22
// koop.server.listen(config.port, () => koop.log.info(`Koop server listening at ${config.port}`))

// You can replace the config.port by process.env.PORT, an environmental variable provided by Heroku
const port = process.env.PORT
koop.server.listen(port, () => koop.log.info(`Koop server listening at ${port}`))

Now the app should be ready for deployment. You can verify the app locally using the heroku local command, which is installed as part of the Heroku CLI.

heroku local web

Your app should now be running on http://localhost:5000/.

Deployment

Now you can finally deploy your app to Heroku.

First, prepare the Heroku credential if you have not signed in at the CLI.

Second, run the heroku create command to set up an empty app instance at Heroku.

Third, push your app code the Heroku with git push heroku master.

Fourth, no, there is no step four.

That’s it. Now you can check your Heroku console and test out your app!

More

Heroku provides a series of articles discussing the Node.js app deployment and you may find them useful in your process:


Improve this page