# Downloading the Node.js Agent

Our Node.js agents (`slnodejs`) are published in the [npm registry](https://www.npmjs.com/package/slnodejs). You download it and all its dependencies using the standard `npm`  commands.

From the various ways to install it, the **installer utility is the recommended best practice**.

## Downloading the latest version from npm <a href="#downloading-latest-version" id="downloading-latest-version"></a>

To always get the newest published version, install directly from npm:

<pre class="language-bash" data-overflow="wrap" data-line-numbers><code class="lang-bash"><strong>npm i slnodejs
</strong></code></pre>

This is useful for testing the latest features, but it may differ from the recommended version set in your dashboard.

## Installing the predefined agent version via the installer utility (Best Practice)

Use the [`slnodejs-installer`](https://www.npmjs.com/package/slnodejs-installer) package to automatically install the **agent version configured in your SeaLights Dashboard Settings page**. This avoids manual scripting and keeps your pipelines aligned with your chosen version.

To run the installer, you must provide your SeaLights Agent Token either by placing a file named `sltoken.txt` in the project root or by setting it as the environment variable `SL_TOKEN`.

{% tabs %}
{% tab title="Linux" %}
{% code overflow="wrap" lineNumbers="true" %}

```sh
# Retrieve the SeaLights Agent Token from your vault/secret manager
export SL_TOKEN=$(vault kv get -field=token secret/sealights)

# Install the agent version defined in your SeaLights Settings
npm install slnodejs-installer
npm list | grep slnodejs 
```

{% endcode %}
{% endtab %}

{% tab title="PowerShell" %}
{% code overflow="wrap" lineNumbers="true" %}

```powershell
# Retrieve the SeaLights Agent Token from your vault/secret manager
$Env:SL_TOKEN = (vault kv get -field=token secret/sealights)

# Install the agent version defined in your SeaLights Settings
npm install slnodejs-installer
npm list | sls slnodejs 
```

{% endcode %}
{% endtab %}

{% tab title="GitLab CI/CD" %}
{% code overflow="wrap" %}

```yaml
install_slnodejs:
  #...
  script:
    # Retrieve the SeaLights Agent Token from your vault/secret manager
    - export SL_TOKEN=$(vault kv get -field=token secret/sealights)
    # Install the agent version defined in your SeaLights Settings
    - npm install slnodejs-installer
    - npm list | grep slnodejs
```

{% endcode %}
{% endtab %}

{% tab title="GitHub Actions" %}
{% code overflow="wrap" %}

```yaml
jobs:
  install:
    #...
    steps:
      - name: Retrieve SL_TOKEN from vault
        run: echo "SL_TOKEN=$(vault kv get -field=token secret/sealights)" >> $GITHUB_ENV
      - run: npm install slnodejs-installer
      - run: npm list | grep slnodejs
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="success" %}
The installer authenticates with your token, retrieves the predefined agent version from your Settings, and installs that exact `slnodejs` version from npm. It also records details in an `install.log` file in the current directory for troubleshooting.
{% endhint %}

## Installing the recommended version via API (Alternative)

If you prefer scripting, you can query the SeaLights Public API to fetch the **recommended version** and install it:

{% tabs %}
{% tab title="Linux" %}
{% code overflow="wrap" lineNumbers="true" %}

```sh
# Retrieve the SeaLights Agent Token from your vault/secret manager
export SL_TOKEN=$(vault kv get -field=token secret/sealights)
# Fetch Agent version defined in Sealights dashboard settings 
$SLVERSION=$(curl -X GET "https://$DOMAIN.sealights.co/api/v2/agents/slnodejs/recommended" -H "accept: application/json" -H "Authorization: Bearer $SL_TOKEN" -L)
# Install Sealights Agent (Recommended version)
npm i slnodejs@$SLVERSION
npm list | grep slnodejs | sed 's/[^a-zA-Z0-9\-]*//;s/@/ version: /'
```

{% endcode %}
{% endtab %}

{% tab title="PowerShell" %}
{% code overflow="wrap" lineNumbers="true" %}

```powershell
# Retrieve the SeaLights Agent Token from your vault/secret manager
$Env:SL_TOKEN = (vault kv get -field=token secret/sealights)
# Fetch Agent version defined in Sealights dashboard settings 
$SLVERSION = Invoke-RestMethod -Uri "https://$DOMAIN.sealights.co/api/v2/agents/slnodejs/recommended" -Headers @{ "accept" = "application/json", "Authorization" = "Bearer $SL_TOKEN"}
# Install Sealights Agent (Recommended version)
npm i "slnodejs@$SLVERSION"
npm list | sls slnodejs | % {$_ -replace '[^a-zA-Z0-9\-]*','' -replace '@',' version: '}
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
In the above examples, replace `$DOMAIN` with your custom dashboard domain&#x20;
{% endhint %}

&#x20;
