> 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/front-end-application/deploying-instrumented-code.md).

# Deploying Instrumented Code

After generating a new folder with the instrumented code of your Front-End application, **the content of this folder needs to be deployed instead of your original code on the server** for the client browser to work against. Below, you’ll find several Best Practices in use among Sealights customers:

{% hint style="warning" %}
In the sample commands below, we refer to your application’s artifact as `dist` folder, as a default.\
Please make sure to update the command according to your specific configuration, and replace the parameter with the path relevant to your project's settings. For example: `apps`, `code`, `js`,…
{% endhint %}

## Deploying the folder containing the instrumented code <a href="#deploying-the-folder-containing-the-instrumented-code" id="deploying-the-folder-containing-the-instrumented-code"></a>

For example, if your original folder was named `'dist'` and the new folder with the instrumented code is '`sl_dist`’, you can follow the steps below:

1. Rename the original folder from ‘`dist`’ to ‘`dist_original`’
2. Use the instrumented folder instead of using one of the following options by renaming the ‘`sl_dist`’ to ‘`dist`’

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

```sh
mv dist dist_original
mv sl_dist dist 
```

{% endtab %}

{% tab title="Windows" %}

```powershell
rename dist dist_original
rename sl_dist dist
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
On Unix/Linux system you also have the ability to define a ‘`dist`’ soft link to the ‘`sl_dist`’ folder.

`ln -s sl_dist dist`
{% endhint %}

## Deploying Instrumentation for several environments (Lab IDs) <a href="#deploying-instrumentation-for-several-environments-lab-ids" id="deploying-instrumentation-for-several-environments-lab-ids"></a>

If you need to instrument your front-end application for several environments and provide accordingly different LabIds (resp. to every context), additional commands are required to manage LabID parameters in your deployment steps. We have described below the most common solutions in use

#### Using slnodejs agent <a href="#using-slnodejs-agent" id="using-slnodejs-agent"></a>

You have the ability to split the single `slnodejs scan` command into a build scan command and several “instrumentations only” commands. For example, below, we’ll instrument the application for two different LabIDs (`MyFirstLab` and `My-2nd-Lab`)

{% code overflow="wrap" %}

```sh
#Build Scan without Instrumentation - Unix
npx slnodejs scan --tokenfFile /path/to/sltoken.txt --buildSessionIdFile buildSessionId --scanDir dist --scmType git --projectRoot /path/to/source/root

#Instrumentation for first environment (i.e. MyFirstLab)
npx slnodejs scan --tokenFile /path/to/sltoken.txt --buildSessionIdFile buildSessionId --labId MyFirstLab --instrumentForBrowsers --instrumentationOnly --scanDir dist --outputPath sl_dist_MyFirstLab 

#Instrumentation for second environment (i.e. My-2nd-Lab)
npx slnodejs scan --tokenFile /path/to/sltoken.txt --buildSessionIdFile buildSessionId --labId My-2nd-Lab --instrumentForBrowsers --instrumentationOnly --scanDir dist --outputPath sl_dist_My-2nd-Lab  
```

{% endcode %}

#### Using a Search and Replace operation <a href="#using-a-search-and-replace-operation" id="using-a-search-and-replace-operation"></a>

Another solution is to execute the `slnodejs scan --instrumentForBrowsers` command with a generic Lab ID that is replaced in the JS files (string operation) prior to the artifact deployment in each environment

{% code overflow="wrap" %}

```sh
Unix:
npx slnodejs scan --tokenFile /path/to/sltoken.txt --buildSessionIdFile buildSessionId --labId sl_LabId_ReplaceMe --instrumentForBrowsers --scanDir dist --outputPath sl_dist --scmType git --projectRoot /path/to/source/root

#Updating LabID for first environment (i.e. MyFirstLab)
find sl_dist -type f -name "*.js" -exec sed -i 's/sl_LabId_ReplaceMe/MyFirstLab/g' {} +

#Updating LabID for second environemnt (i.e. My-2nd-Lab)
find sl_dist -type f -name "*.js" -exec sed -i 's/sl_LabId_ReplaceMe/My-2nd-Lab/g' {} + 
```

{% endcode %}

## Validating the Instrumentation and build number in the JS source from the Browser <a href="#validating-the-instrumentation-and-build-number-in-the-js-source-from-the-browser" id="validating-the-instrumentation-and-build-number-in-the-js-source-from-the-browser"></a>

In your browser, open the source code of your JS page: is there the Sealights' instrumentation code and the right build number at the beginning of the page ? If Yes, all is set.

<figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FRyBDnEuFxdG0fMygysXG%2Fimage.png?alt=media&amp;token=08bb8fcc-75b6-4ede-9d29-40b6ac0d8d65" alt=""><figcaption></figcaption></figure>


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/legacy-commands-deprecated/front-end-application/deploying-instrumented-code.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
