This repository is the home of Heroku Cloud Native Buildpacks for Node.js applications. These buildpacks build Node.js application source code into application images with minimal configuration.
Important
This is a collection of Cloud Native Buildpacks, and is a component of the Heroku Cloud Native Buildpacks project, which is in preview. If you are instead looking for the Heroku Classic Buildpack for Node.js (for use on the Heroku platform), you may find it here.
Note
Before getting started, ensure you have the pack CLI installed. Installation
instructions are available here.
To build a Node.js application codebase into a production image:
$ cd ~/workdir/sample-nodejs-app
$ pack build sample-app --builder heroku/builder:24Then run the image:
docker run --rm -it -e "PORT=8080" -p 8080:8080 sample-appThe heroku/nodejs buildpack requires a valid package.json to be present to build.
In order to install dependencies, a valid npm, yarn, or pnpm lockfile must be present.
To select a Node.js version, specify it via engines.node in package.json.
For example, to select the latest release of Node.js version 22, modify your package.json like this:
{
"engines": {
"node": "22.x"
}
}
Note
This field supports the same semantic versioning syntax as package.json.
E.g.; ^1.0, ~1.0, 1.x, etc. See https://semver.npmjs.com/ for more examples.
Note
If no Node.js version is specified, the latest LTS version will be used. We highly suggest specifying a version to prevent surprise changes.
To select a package manager version, specify it via:
-
engines.yarn,engines.npm,engines.pnpmFor example, to select npm, modify your
package.jsonlike this:{ "engines": { "npm": "11.x" } }The version declared in the
enginefields supports the same semantic versioning syntax aspackage.json. E.g.;^1.0,~1.0,1.x, etc. See https://semver.npmjs.com/ for more examples. -
packageManagerinpackage.jsonFor example, to select pnpm, modify your
package.jsonlike this:{ "engines": { "packageManager": "[email protected]" } }The version declared in the
packageManagerfield must be an exact version for compatibility with local use of Corepack tooling.
Note
If no package manager is specified, the npm version bundled with Node.js will be used. We highly suggest specifying a package manager and version to prevent surprise changes.
The following scripts from package.json will be executed by the configured package manager in the order listed:
heroku-prebuildheroku-buildorbuild(if both are present, onlyheroku-buildwill execute)heroku-postbuild
If any of the above scripts are not defined in package.json they will be skipped.
Issues and pull requests are welcome. See our contributing guidelines if you would like to help.
