> For the complete documentation index, see [llms.txt](https://docs.sealights.io/knowledgebase/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/generating-a-session-id.md).

# Generating a session ID

Before running the build scan and tests, create a session ID. Pass the same ID to each step so SeaLights links them as one complete cycle.

{% hint style="info" %}
See '[Generating an Agent token](https://docs.sealights.io/knowledgebase/settings/token-access-and-management#token-list-and-token-creation-2)' for instructions on how to generate a token.
{% endhint %}

## Generating a session ID in Node.js <a href="#generating-a-session-id-in-node.js" id="generating-a-session-id-in-node.js"></a>

Use `config` to open the build session and write `buildSessionId`.

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

```bash
BUILD_NAME="$(date -u +"%Y%m%d_%H%M%S")"

npx slnodejs config \
  --tokenFile ./sltoken.txt \
  --appName "myApp" \
  --branchName "main" \
  --buildName "$BUILD_NAME"
```

{% endcode %}
{% endtab %}

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

```yaml
- name: Generate SeaLights Build Session ID
  env:
    SL_TOKEN: ${{ secrets.SL_TOKEN }}
  run: |
    npx slnodejs config \
      --token "$SL_TOKEN" \
      --appName "${{ github.event.repository.name }}" \
      --branchName "${{ github.ref_name }}" \
      --buildName "${{ github.run_id }}"
```

{% endcode %}
{% endtab %}

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

```powershell
$BuildName = Get-Date -Format "yyyyMMdd_HHmmss"

npx slnodejs config `
  --tokenFile .\sltoken.txt `
  --appName "myApp" `
  --branchName "main" `
  --buildName $BuildName
```

{% endcode %}
{% endtab %}

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

```yaml
- script: |
    npx slnodejs config \
      --token "$(SL_TOKEN)" \
      --appName "$(Build.Repository.Name)" \
      --branchName "$(Build.SourceBranchName)" \
      --buildName "$(Build.BuildId)"
  displayName: Generate SeaLights Build Session ID
```

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

{% hint style="info" %}
Each successful call creates the data structures for this build.

The `appName` / `branchName` / `buildName` trio must be unique on every run.

Locally, use a timestamp for `buildName`.

In CI, use the platform run ID or build ID.
{% endhint %}

{% hint style="warning" %}
**The most common cause of the "Module already exists" error** is reusing the same `buildName`.
{% endhint %}

{% hint style="info" %}
See [Command Reference](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/command-reference.md#configure-a-session-and-create-session-id) for the full parameter details.
{% endhint %}

## Using the session ID <a href="#using-the-session-id" id="using-the-session-id"></a>

The command prints the session ID and writes it to `buildSessionId`. Reuse that file in later agent commands, or export it as an environment variable.

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

```bash
export SL_BUILD_SESSION_ID=$(cat buildSessionId)
```

{% endcode %}
{% endtab %}

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

```yaml
- name: Export SeaLights Build Session ID
  run: echo "SL_BUILD_SESSION_ID=$(cat buildSessionId)" >> $GITHUB_ENV
```

{% endcode %}
{% endtab %}

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

```powershell
$env:SL_BUILD_SESSION_ID = (Get-Content .\buildSessionId).Trim()
```

{% endcode %}
{% endtab %}

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

```yaml
- script: |
    SESSION_ID=$(cat buildSessionId)
    echo "##vso[task.setvariable variable=SL_BUILD_SESSION_ID]$SESSION_ID"
  displayName: Export SeaLights Build Session ID
```

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/generating-a-session-id.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
