App Platform NodeJS Buildpack

NodeJS

heroku-buildpack-nodejs is utilized as the buildpack for detecting and building your NodeJS applications.

You can view the README for a full list of configuration options available to the buildpack.

Detection

A NodeJS app is detected based on the existence of the following file at the root of your source code:

package.json

Additionally, either a Yarn lockfile (yarn.lock) or an NPM lockfile (package-lock.json) is required. If both exist, Yarn is preferred.

Customization

Node Version

You can customize the Node version used by specifying the version in the engines section of your package.json:

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

NPM

You can customize the NPM version used by specifying the version in the engines section of your package.json:

{
  "engines": {
    "npm": "~1.0.20"
  }
}

Yarn

You can customize the Yarn version used by specifying the version in the engines section of your package.json:

{
  "engines": {
    "yarn": "^0.14.0"
  }
}

Caching

The buildpack automatically caches and re-uses the node_modules directory between builds. After the package manager’s install command is run (yarn install or npm install), the node_modules directory is stored in the build cache along with snapshot of the package manager’s lockfile. In subsequent builds, the cached node_modules directory will be restored only if the lockfile’s contents are identical to cached version. Otherwise, the cache will be discarded.

Clearing the Cache

If your app is failing to build and you suspect that the issue is related to node_modules caching, you can force clear the cache and start a new build. To do this in the control panel, navigate to your app, click the Actions menu, and then select Force Build and Deploy.

Force Build and Deploy screen with Clear Build Cache checked

In the Force Build and Deploy window, select the Clear Build Cache option, and then click on the “Deploy” button. This clears the build cache and starts a new deployment.