# Generating a session ID

Before running the build scan and tests, you need to create a session ID. The session ID is provided to each step in order to link them together 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>

Generating a session ID in Node.js is done using the SeaLights Node.js Agent with the config flag

{% code overflow="wrap" lineNumbers="true" %}

```shell
npx slnodejs config --tokenfile ./sltoken.txt --appname "myApp" --branch "master" --build "1"
```

{% endcode %}

{% hint style="info" %}
Each time this command successfully connects to your SeaLights instance, data structures will be created to store the build map, test monitoring data, and, generally, data pertaining to this build of your application.

**Each time you call this command, the appname / branch / buildname trio needs to be unique**. Typically, the `buildname` changes each time, as you will scan your build once following each build of your application.

You can provide a timestamp for the `buildname` parameter. For example: `--build $(date +"%y%m%d_%H%M")` (Linux) or `--build $(Get-Date -Format "yyyMMdd_HHmm")` (Windows PowerShell)
{% endhint %}

{% hint style="warning" %}
**The most common cause of the "Module already exists" error message** indicates that the config command was likely called without changing the `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 session ID will be printed to the console output and a file called '`buildSessionId`' will be generated containing it. The file can be used as is in the agent parameters or to fill in an environment parameter in a command line.

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

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

{% endcode %}
{% endtab %}

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

```powershell
set /p SL_BUILD_SESSION_ID=<buildSessionId
```

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


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
