# Scanning a Build

## Scanning a build <a href="#scanning-a-build" id="scanning-a-build"></a>

Scanning a build in Node.js is done using the Node.js Build scanner with the build flag.

{% code overflow="wrap" %}

```sh
npx slnodejs scan --tokenfile ./sltoken.txt --buildsessionidfile buildSessionId --workspacepath "." --scm git --es6Modules
```

{% endcode %}

{% hint style="warning" %}
For React applications, you should add the flag: `--babylonPlugin jsx`. To scan both `.ts` and `.tsx` files, you should add the flag: `--babylonPlugins typescript,jsx`
{% endhint %}

{% hint style="info" %}

* In order to ignore specific files or folders during the Scan operation, please refer to [ignoring-files-or-folders](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/ignoring-files-or-folders "mention")
* For "`JavaScript heap out of memory`" errors while running scan, see: [nodejs-javascript-heap-out-of-memory](https://docs.sealights.io/knowledgebase/setup-and-configuration/troubleshooting-faq/node-javascript/nodejs-javascript-heap-out-of-memory "mention")
* See [#scanning-a-build](https://docs.sealights.io/knowledgebase/setup-and-configuration/go-agent/go-agent-v1/command-reference#scanning-a-build "mention") for full parameter details
  {% endhint %}

## Scanning a ts-node build <a href="#scanning-a-ts-node-build" id="scanning-a-ts-node-build"></a>

Scanning a build in Node.js is done using the Node.js Build scanner with the scan command flag and requires:

* explicit type of files (`.ts` and/or `.tsx`) in a dedicated environment variable `SL_fileExtensions`
* scan the application files with the `workspacepath` parameter pointing to the source files directory (`.ts`)

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

```sh
export SL_fileExtensions=".ts,.tsx"

npx slnodejs scan --tokenfile /path/to/sltoken.txt --buildsessionidfile buildSessionId --workspacepath "./src" --scm git 
```

{% endcode %}
{% endtab %}

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

```powershell
export SL_fileExtensions=".ts,.tsx"

call npx slnodejs scan --tokenfile \path\to\sltoken.txt --buildsessionidfile buildSessionId --workspacepath ".\src" --scm git 
```

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

## Scanning multi modules <a href="#scanning-multi-modules" id="scanning-multi-modules"></a>

If you want to report separate parts of the application as separate modules, you can do so by scanning each part with the `--uniqueModuleId` option.

When you finish reporting all the modules, you need to send the event with the `buildend` command and either the `--ok` or `--failed` depending on the result of your build process.

{% hint style="warning" %}
It is important to always use the exact **same module names each time** you report a new build.
{% endhint %}

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

```sh
npx slnodejs scan --tokenfile ./path/to/sltoken.txt --buildsessionidfile buildSessionId --workspacepath "." --scm git --es6Modules --uniqueModuleId module-name-one 
npx slnodejs scan --tokenfile ./path/to/sltoken.txt --buildsessionidfile buildSessionId --workspacepath "." --scm git --es6Modules --uniqueModuleId module-name-two

npx slnodejs buildend --tokenfile ./path/to/sltoken.txt --buildsessionidfile buildSessionId --ok
```

{% endcode %}
