anchor.diff:  ---
  -title: Node.js CNB
  +title: Cloud-Native Buildpacks for Node.js
   owner: Buildpacks
   ---
   
  -##<a id="specifying-node-engine-version"></a> Specifying a Node Engine Version
  -The Node Engine CNB allows application developers to specify a version of
  -Node.js to use during deployment.  This version can be specified in a number of
  -ways, including via `.nvmrc`, `buildpack.yml`, or `package.json` files.  When
  -specifying a version of the Node.js engine, application developers must make
  -sure to choose a version that is available within the buildpack.
  +This topic describes creating and configuring cloud-native buildpacks (CNBs) for Node.js.
   
  -When specifying a version, keep in mind that the buildpack prioritizes the
  -versions specified in each of the possible configuration locations with the
  -following precedence.
  +
  +## <a id="specifying-node-engine-version"></a> Specifying a Node Engine Version
  +
  +The Node Engine CNB allows app developers to specify a version of Node.js to use during deployment. This version can be specified in a number of ways, including through `.nvmrc`, `buildpack.yml`, or `package.json` files. When specifying a version of the Node.js engine, you must choose a version that is available within the buildpack.
  +
  +When you specify a version, the buildpack prioritizes the versions specified in each possible configuration location with the following precedence.
   
   **(highest)** `buildpack.yml` > `package.json` > `.nvmrc` **(lowest)**
   
  -**Using buildpack.yml**
  +### <a id='buildpack-yml'></a> Using buildpack.yml
   
  -Including the follow snippet in your `buildpack.yml` file will configure the
  -buildpack to use `v12.12.0` of Node.js when building and launching your
  -application.
  +To configure the buildpack to use Node.js v12.12.0 when deploying your app, include the values below in your `buildpack.yml` file:
   
   ```
   ---
  
positive.code:   version: 12.12.0
  ```
  
  **Using package.json**
  
  Applications using `npm` can specify the version of Node.js used during the
  build and launch phases of their application deployment by configuring the
  `engines` field in the `package.json` file. The following snippet in your
  `package.json` will configure the buildpack to use `v12.12.0` of Node.js when
  building and launching your application.
  
  ```
  {
  
negative.code:   optimize-memory: true
  ```
  
  ### <a id="optimize-memory-env-var"></a> Using the OPTIMIZE_MEMORY Environment Variable
  
  To enable memory optimization through the `OPTIMIZE_MEMORY` environment variable, set it to `true`.
  
  
  ## <a id="package-management-with-npm"></a> Package Management with NPM
  
  Many Node.js apps require a number of third-party libraries to perform common tasks and behaviors. NPM is an option for managing these third-party dependencies that the Node.js CNB fully supports. Including a `package.json` file in your app source code begins the NPM installation process. The sections below describe the NPM installation process.
  
  ### <a id="npm-installation-process"></a> NPM Installation Process
  
  NPM supports several distinct methods for installing your package dependencies. Specifically, the Node.js CNB runs a combination of the `npm install`, `npm rebuild`, and `npm ci` commands to build your app with the right set of dependencies. When deciding which installation process to use, the Node.js CNB consults your app source code, looking for the presence of specific files or directories. For more information about the `npm install` command, see [npm-install](https://docs.npmjs.com/cli-commands/install) in the NPM documentation. For more information about the `npm rebuild` command, see [npm-rebuild](https://docs.npmjs.com/cli-commands/rebuild.html) in the NPM documentation. For more information about the `npm ci` command, see [npm-ci](https://docs.npmjs.com/cli-commands/ci.html) in the NPM documentation.
  
  These sections describe the files and directories you can include in your source code, and which installation process the Node.js CNB uses when these files and directories are present.
  
  #### <a id="package-lock-json"></a> package-lock.json
  
  The `package-lock.json` file is machine-generated file the Node.js CNB creates during the `npm install` process. For more information, see [npm-package-lock.json](https://docs.npmjs.com/files/package-lock.json) in the NPM documentation.
  
  #### <a id="node-modules"></a> node_modules
  
  The `node_modules` directory contains vendored copies of all the packages the Node.js CNB installs during the `npm install` process. For more information, see the [Node Modules](https://docs.npmjs.com/files/folders.html#node-modules) section of the _npm-folders_ topic in the NPM documentation.
  
  #### <a id="npm-cache"></a> npm-cache
  
  he `npm-cache` directory contains a content-addressable cache that stores all HTTP request and package-related data. Additionally, including a cache ensures that the app can be built entirely offline.
  
  To populate a `npm-cache` directory:
  
  1. Navigate to your source code directory.
  
  1. Run:
  
      ```
      npm ci --cache npm-cache
      ```
  
  For more information about the NPM cache, see [npm-cache](https://docs.npmjs.com/cli/cache) in the NPM documentation.
  
  #### <a id="installation-process"></a> Determining an Installation Process
  
  The table below shows the process the Node.js CNB uses to determine an installation process for NPM packages. When a combination of the files and directories described in [NPM Installation Process](#npm-installation-process) is present, the Node.js CNB uses an installation process that ensures the correct third-party dependencies are installed during the build process.
  
  | `package-lock.json` | `node_modules` | `npm-cache` | Command |
  | ------------------- | -------------- | ----------- | ------- |
  | X | X | X | `npm install` |
  | X | X | ✓ | `npm install` |
  | X | ✓ | X | `npm rebuild` and `npm install` |
  | X | ✓ | ✓ | `npm rebuild` and `npm install` |
  | ✓ | X | X | `npm ci` |
  | ✓ | X | ✓ | `npm ci` |
  | ✓ | ✓ | X | `npm rebuild` and `npm install` |
  | ✓ | ✓ | ✓ | `npm ci` |
  
  
  ## <a id="package-management-with-yarn"></a> Package Management with Yarn
  
  Many Node.js apps require a number of third-party libraries to perform common tasks and behaviors. Yarn is an alternative option to NPM for managing these third-party dependencies that the Node.js CNB fully supports. Including `package.json` and `yarn.lock` files in your app source code begins the Yarn installation process.
  
  ### <a id="yarn-installation-process"></a> Yarn Installation Process
  
  The Node.js CNB runs `yarn install` and `yarn check` to ensure that third-party dependencies are properly installed. Including a `yarn.lock` file in your app source code causes the Node.js CNB to use the Yarn installation process.
  
  The `yarn.lock` file contains a fully resolved set of package dependencies that Yarn manages. For more information, see [yarn.lock](https://yarnpkg.com/lang/en/docs/yarn-lock/) in the Yarn documentation.
  
  
  ## <a id="start-command"></a> Start Command
  
  As part of the build process, the Node.js CNB determines a start command for your app. The start command differs depending on which package management tooling the Node.js CNB uses. If the Node.js CNB uses `npm-cnb` to install packages with `npm`, the start command is `npm start`. If the Node.js CNB uses `yarn-cnb` to install packages using `yarn`, the start command is `yarn start`.
  