> 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/legacy-commands-deprecated/backend-server-application/running-backend-server.md).

# Running Backend Server

To collect code coverage for a Node.js backend application, the SeaLights Node.js agent can be attached in one of two ways:

* Non-Intrusive Approach (Using `preload.js` with `NODE_OPTIONS`)
* Wrapper Command (Using `slnodejs run`)

{% hint style="success" %}
Once your application starts with the agent, it should appear under **Live Agents Monitor** in the SeaLights Cockpit.
{% endhint %}

## Non-Intrusive Approach (Using `preload.js` with `NODE_OPTIONS`)

This method is ideal when you **cannot or prefer not to modify the application’s execution command**, such as in Docker containers, `pm2`, or CI environments.

The SeaLights agent provides a `preload.js` script that can be injected into the process using the `NODE_OPTIONS` environment variable.

```bash
export SL_tokenfile=./sltoken.txt
export SL_buildsessionidfile=buildSessionId
export SL_labid=my_lab_id
export NODE_OPTIONS="--require ./node_modules/slnodejs/lib/preload.js"

node ./server/app.js
```

> 💡 **Note**: This method also works with TypeScript apps run via `ts-node`, e.g., `ts-node ./server/app.ts`. No special handling is needed beyond setting `NODE_OPTIONS` correctly.

## Wrapper Command (Using `slnodejs run`)

This method wraps the application’s startup command using the SeaLights CLI runner. It gives you full control over parameters and visibility into agent behavior.

### Generic Node.js App

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

```bash
npx slnodejs run --tokenFile ./sltoken.txt --buildSessionIdFile buildSessionId --labId my_lab_id --scanDir ./server --useinitialcolor true -- ./server/app.js
```

{% endcode %}
{% endtab %}

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

```powershell
npx slnodejs run --tokenFile .\sltoken.txt --buildsessionidfile buildSessionId --labId my_lab_id --scanDir .\server --useinitialcolor true -- .\server\app.js
```

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

### TypeScript App Using `ts-node`

SeaLights only supports `ts-node` apps when started with: `node -r ts-node/register ./server/app.ts`

Wrap this format with the agent:

{% tabs %}
{% tab title="Linux" %}

<pre class="language-bash" data-overflow="wrap"><code class="lang-bash"><strong>npx slnodejs run --tokenFile ./sltoken.txt --buildSessionIdFile buildSessionId --labId my_lab_id --scanDir ./server --useinitialcolor true --useSlNode2 -- -r ts-node/register ./server/app.ts
</strong></code></pre>

{% endtab %}

{% tab title="Powershell" %}
{% code overflow="wrap" %}

```powershell
npx slnodejs run --tokenFile .\sltoken.txt --buildSessionIdFile buildSessionId --labId my_lab_id --scanDir .\server --useinitialcolor true --useSlNode2 -- -r ts-node/register .\server\app.ts
```

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

## Additional Notes

To verify the agent is running, you can run the following command:

{% tabs %}
{% tab title="Linux" %}

```sh
ps -ef | grep slnodejs
```

{% endtab %}

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

```powershell
Get-WmiObject Win32_Process | Where-Object { $_.CommandLine -like "*slnodejs*" } | Select-Object CommandLine, ProcessId
```

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

* We recommend using the `--labId` parameter (or `SL_labid` for preload) to correlate your test and listener sessions. If `labid` is not set, the session ID will be used automatically.
* For full parameter details, see the Node.js Command Reference.


---

# 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/legacy-commands-deprecated/backend-server-application/running-backend-server.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.
