Title: Manage dependencies in Node.js
Author: WordPress VIP Documentation
Published: April 8, 2022
Last modified: April 21, 2025

---

 1. [Node.js on VIP](https://docs.wpvip.com/node-js/)
 2. Manage dependencies in Node.js

#  Manage dependencies in Node.js

Node.js applications on the VIP Platform must use `[npm](https://docs.npmjs.com/about-npm)`
to manage their dependencies. Other dependency managers such as `yarn` are not supported.

## Installing dependencies

Prior to building and running a Node.js application, VIP installs the application’s**
production dependencies** with: 

    ```wp-block-preformatted
    npm install --production 
    ```

This step installs the dependencies listed in the `dependencies` section of an application’s`
package.json` . It does not install the dependencies listed in the `devDependencies`
section.

Any dependency that is required to build or run an application on a VIP Platform
environment—including build tools like [Webpack](https://webpack.js.org/) or [Sass](https://sass-lang.com/)—
should be installed as a production dependency.

Production dependencies are installed and saved using the `--save` option:

    ```wp-block-preformatted
    npm install --save webpack 
    ```

For development dependencies, use the `--save-dev` option:

    ```wp-block-preformatted
    npm install --save-dev eslint
    ```

The VIP Platform currently runs `npm install` instead of `npm clean-install` (`npm
ci`) when installing an application’s production dependencies. The `npm install`
command will attempt to resolve any dependency conflicts between `package.json` 
and `package-lock.json` and is therefore less likely to fail. If needed, customers
are encouraged to share requests for updates to this default behavior in [VIP’s Feedback Portal](https://docs.wpvip.com/vip-support/vip-product-feedback/).

## Version management

Both `package.json` and `package-lock.json` should be committed to a [wpcomvip GitHub repository](https://docs.wpvip.com/wpcomvip-github-repository/).
Providing `package-lock.json` enables every system, including the VIP platform, 
to install and use the exact same dependency tree.

VIP also supports `npm-shrinkwrap.json`. If `npm-shrinkwrap.json` is present, it
takes precedence over `package-lock.json`. Though both files perform similar functions,
[the differences between `npm-shrinkwrap.json` and `package-lock.json`](https://docs.npmjs.com/cli/v8/configuring-npm/package-lock-json#package-lockjson-vs-npm-shrinkwrapjson)
should be considered carefully before adding `npm-shrinkwrap.json` to an application.

When developing code locally, check that the dependencies installed locally match
those specified by `package-lock.json` in the current working branch. If there are
any discrepancies, or to just eliminate doubt, remove the `node_modules` directory
entirely and reinstall the dependencies.

**Caution**

The `node_modules` directory should not be committed to a wpcomvip GitHub repository.
To ensure that dependencies are not accidentally committed, the `node_modules` directory
has been added to `.gitignore` in the [vip-go-node-skeleton](https://github.com/Automattic/vip-go-node-skeleton/tree/27c12a917d7b2ec40a82fce742d0f6f9be4935db)(
and also [vip-go-skeleton](https://github.com/Automattic/vip-go-skeleton) for WordPress
applications).

## Private dependencies

Using private dependencies is not recommended because they can introduce issues 
that are difficult to troubleshoot. For example, if an authorization token used 
to load private dependencies is rotated or expires, builds may seem to fail spontaneously.
Additionally, using private dependencies to manage application secrets does not 
impart any additional protection and may contribute to a false sense of security.
Instead, [environment variables can be used](https://docs.wpvip.com/manage-environment-variables/)
to more securely manage secrets.

If private dependencies are necessary, [private npm packages](https://docs.npmjs.com/creating-and-publishing-private-packages)
can be used to load them:

 1. Publish the private code as one or more private npm packages and install them as
    dependencies of the application.
 2. Generate an [npm access token](https://docs.npmjs.com/about-access-tokens) that
    has permission to read the private packages.
 3. [Set an environment variable](https://docs.wpvip.com/manage-environment-variables/)
    with the access token as its value.
 4. Commit an [`.npmrc` file](https://docs.npmjs.com/cli/v8/configuring-npm/npmrc) 
    that references the environment variable name:

    ```wp-block-preformatted
    # comments begin with # or ;
    //registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}
    ```

The token will be used by `npm` to install the private packages on the VIP platform.
This approach can be used to install private packages from one or more custom registries
by adding additional entries to the `.npmrc` file:

    ```wp-block-preformatted
    # official NPM registry
    //registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}

    # myorg custom registry
    @myorg:registry=https://example.com/myorg/
    //example.com/myorg/:_authToken=${MYORG_NPM_AUTH_TOKEN}
    ```

Make sure to use the curly-brace notation when referencing environment variables;
omitting them will fail silently. Also note that `npm` will not read environment
variables from `.env` files.

Committing the authorization tokens directly to the application’s GitHub repository,
either in `.npmrc` or in `package.json`, is not recommended.

**Note**

Previous versions of this documentation recommended the use of a special `NPM_TOKEN`
environment variable, which would automatically configure an `.npmrc` file on the
VIP Platform. While this approach still works, it should be considered deprecated
and its support will eventually be removed. If an `.npmrc` file is committed to 
the application’s GitHub repository, it will take precedence over an `NPM_TOKEN`
environment variable.

## Workspaces

[Workspaces are an `npm` feature](https://docs.npmjs.com/cli/v8/using-npm/workspaces)
that allow projects to reference local code as modules. This is often leveraged 
in “monorepos” to develop subpackages that are maintained inside of a parent codebase.
The VIP Platform supports workspaces when they are placed in a directory named `
packages/` in the root of the codebase. Using any other path or employing symlinks
will result in a build failure at the `npm install` step.

Last updated: April 21, 2025