> ## 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:extensions.bzl

> Bazel rules_nodejs bzlmod module extensions for registering a Node.js toolchain in MODULE.bazel, with version pinning from .nvmrc for JavaScript builds.

<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/extensions.bzl)
</Callout>

Module extensions for nodejs toolchain registration in MODULE.bazel

Example usage, assuming a `.nvmrc` file is present in the same directory as the `MODULE.bazel` file:

```python theme={null}
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
node.toolchain(node_version_from_nvmrc = "//:.nvmrc")
use_repo(node, "nodejs_toolchains")
```

## Module extension: `node`

### Tag: `toolchain`

<ParamField body="name" type="name" default={`nodejs`}>
  Base name for generated repositories
</ParamField>

<ParamField body="node_version" type="string" default={`22.22.0`}>
  Version of the Node.js interpreter
</ParamField>

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

  This is recommended to ensure Bazel uses the same Node.js version as non-Bazel tooling.
  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="boolean" default={`False`}>
  Set headers field in NodeInfo provided by this toolchain.

  Required to compile native code into a Node.js binary.
  This setting creates a dependency on a c++ toolchain.
</ParamField>

<ParamField body="node_urls" type="list of strings" 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_repositories" type="dictionary: String → List of strings" 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>
