> ## Documentation Index
> Fetch the complete documentation index at: https://site.aspect.build/llms.txt
> Use this file to discover all available pages before exploring further.

# @rules_nodejs//nodejs:repositories.bzl

> Bazel rules_nodejs repository rules including nodejs_repositories to install rules_nodejs WORKSPACE dependencies for legacy Node.js JavaScript setups.

<Callout icon="book">
  Documentation for [@rules\_nodejs@v6.7.3](https://registry.bazel.build/modules/rules_nodejs/6.7.3) -- <Icon icon="github" iconType="brands" /> [View source](https://github.com/bazel-contrib/rules_nodejs/blob/v6.7.3/nodejs/repositories.bzl)
</Callout>

Rules to be called from the users WORKSPACE

## Function: `nodejs_repositories`

To be run in user's WORKSPACE to install rules\_nodejs dependencies.

This rule sets up node, npm, and npx. The versions of these tools can be specified in one of three ways

### Simplest Usage

Specify no explicit versions. This will download and use the latest Node.js that was available when the
version of rules\_nodejs you're using was released.

### Forced version(s)

You can select the version of Node.js to download & use by specifying it when you call node\_repositories,
using a value that matches a known version (see the default values)

### Using a custom version

You can pass in a custom list of Node.js repositories and URLs for node\_repositories to use.

#### Custom Node.js versions

To specify custom Node.js versions, use the `node_repositories` attribute

```python theme={null}
nodejs_repositories(
    node_repositories = {
        "10.10.0-darwin_amd64": ("node-v10.10.0-darwin-x64.tar.gz", "node-v10.10.0-darwin-x64", "00b7a8426e076e9bf9d12ba2d571312e833fe962c70afafd10ad3682fdeeaa5e"),
        "10.10.0-linux_amd64": ("node-v10.10.0-linux-x64.tar.xz", "node-v10.10.0-linux-x64", "686d2c7b7698097e67bcd68edc3d6b5d28d81f62436c7cf9e7779d134ec262a9"),
        "10.10.0-windows_amd64": ("node-v10.10.0-win-x64.zip", "node-v10.10.0-win-x64", "70c46e6451798be9d052b700ce5dadccb75cf917f6bf0d6ed54344c856830cfb"),
    },
)
```

These can be mapped to a custom download URL, using `node_urls`

```python theme={null}
nodejs_repositories(
    node_version = "10.10.0",
    node_repositories = {"10.10.0-darwin_amd64": ("node-v10.10.0-darwin-x64.tar.gz", "node-v10.10.0-darwin-x64", "00b7a8426e076e9bf9d12ba2d571312e833fe962c70afafd10ad3682fdeeaa5e")},
    node_urls = ["https://mycorpproxy/mirror/node/v{version}/{filename}"],
)
```

A Mac client will try to download node from `https://mycorpproxy/mirror/node/v10.10.0/node-v10.10.0-darwin-x64.tar.gz`
and expect that file to have sha256sum `00b7a8426e076e9bf9d12ba2d571312e833fe962c70afafd10ad3682fdeeaa5e`

See the [the repositories documentation](https://docs.aspect.build/bazel/javascript/rules_nodejs/nodejs_repositories) for how to use the resulting repositories.

### Using a custom node.js.

To avoid downloads, you can check in a vendored node.js binary or can build one from source.
See [toolchains](/bazel/javascript/rules_nodejs/nodejs_toolchain).

### Parameters

<ParamField body="name" type="unknown" required>
  Unique name for the repository rule
</ParamField>

<ParamField body="node_download_auth" type="unknown" default={`{}`}>
  Auth to use for all url requests.

  Example: `{ "type": "basic", "login": "<UserName>", "password": "<Password>" }`
</ParamField>

<ParamField body="node_repositories" type="unknown" default={`{}`}>
  Custom list of node repositories to use

  A dictionary mapping Node.js versions to sets of hosts and their corresponding (filename, strip\_prefix, sha256) tuples.
  You should list a node binary for every platform users have, likely Mac, Windows, and Linux.

  By default, if this attribute has no items, we'll use a list of all public Node.js releases.
</ParamField>

<ParamField body="node_urls" type="unknown" default={`["https://nodejs.org/dist/v{version}/{filename}"]`}>
  List of URLs to use to download Node.js.

  Each entry is a template for downloading a node distribution.

  The `{version}` parameter is substituted with the `node_version` attribute,
  and `{filename}` with the matching entry from the `node_repositories` attribute.
</ParamField>

<ParamField body="node_version" type="unknown" default={`22.22.0`}>
  The specific version of Node.js to install
</ParamField>

<ParamField body="node_version_from_nvmrc" type="unknown" default={`None`}>
  The .nvmrc file containing the version of Node.js to use.

  If set then the version found in the .nvmrc file is used instead of the one specified by node\_version.
</ParamField>

<ParamField body="include_headers" type="unknown" default={`False`}>
  Set headers field in NodeInfo provided by this toolchain.

  This setting creates a dependency on a c++ toolchain.
</ParamField>

<ParamField body="kwargs" type="unknown">
  Additional parameters
</ParamField>

## Function: `node_repositories`

Deprecated. Use nodejs\_repositories instead.

### Parameters

<ParamField body="kwargs" type="unknown">
  Parameters to forward to nodejs\_repositories rule.
</ParamField>

## Function: `nodejs_register_toolchains`

Convenience macro for users which does typical setup.

* create a repository for each built-in platform like "node16\_linux\_amd64" -
  this repository is lazily fetched when node is needed for that platform.
* create a convenience repository for the host platform like "node16\_host"
* create a repository exposing toolchains for each platform like "node16\_platforms"
* register a toolchain pointing at each platform

Users can avoid this macro and do these steps themselves, if they want more control.

### Parameters

<ParamField body="name" type="unknown" default={`nodejs`}>
  base name for all created repos, like "node16"
</ParamField>

<ParamField body="register" type="unknown" default={`True`}>
  whether to call Bazel register\_toolchains on the created toolchains.
  Should be True when used from a WORKSPACE file, and False used from bzlmod
  which has its own toolchain registration syntax.
</ParamField>

<ParamField body="kwargs" type="unknown">
  passed to each nodejs\_repositories call
</ParamField>

## Function: `rules_nodejs_dependencies`
