# Configuring the scanner

The analysis parameters are used to set up the project analysis. For more information, see [#general-configuration-guidelines](https://docs.sonarsource.com/sonarqube-cloud/analysis-parameters/configuration-overview#general-configuration-guidelines "mention").

Depending on your tool environment and strategy, and on the analysis parameter (global or not, must be securely passed or not), you may choose one or the other setup method described on this page.

## Introduction to the analysis parameters setup <a href="#introduction" id="introduction"></a>

The SonarScanner for NPM reads or receives parameters from different sources:

* It gets analysis parameters through its APIs.
* It reads analysis parameters from `package.json`.
* It reads analysis parameters from environment variables.
* It reads parameters from the `sonar-project.properties` file.
* It gets the parameters that were set in the SonarQube Cloud UI.
* Some parameters are assigned a default value.

The table below lists the different configuration methods in the order of priority in which the SonarScanner for NPM processes the corresponding parameters.

<table><thead><tr><th width="106">Priority (higher to lower)</th><th width="187">Method</th><th>Description</th></tr></thead><tbody><tr><td>1</td><td>API parameters</td><td>Parameters can be provided to the scanner either through the JS code API or through the command line API.</td></tr><tr><td>2</td><td>Environment variables</td><td>Some parameters can be stored in environment variables on the CI/CD host.</td></tr><tr><td>4</td><td>Project configuration file</td><td>Parameters can be defined in the <code>sonar-project.properties</code> file stored in the project root directory.</td></tr><tr><td>3</td><td><code>package.json</code></td><td>The scanner reads some analysis parameters from fields of the package.json file.</td></tr><tr><td>5</td><td>Default values</td><td>Some parameters are assigned a default value. The parameters considered here are parameters that cannot be set in the UI.</td></tr><tr><td>6</td><td>UI</td><td>Parameters can be set in the UI for a given project.</td></tr></tbody></table>

### Analysis parameters read from package.json <a href="#analysis-parameters-read-from-packagejson" id="analysis-parameters-read-from-packagejson"></a>

The SonarScanner for NPM parses the `package.json` file of the project to be analyzed and reads the value of the parameters below from the corresponding `package.json` field. For information about the listed analysis parameters, see [parameters-not-settable-in-ui](https://docs.sonarsource.com/sonarqube-cloud/analyzing-source-code/analysis-parameters/parameters-not-settable-in-ui "mention").

<table><thead><tr><th width="243">Analysis parameter</th><th>package.json field</th></tr></thead><tbody><tr><td><code>sonar.projectName</code></td><td><code>name</code></td></tr><tr><td><code>sonar.projectVersion</code></td><td><code>version</code></td></tr><tr><td><code>sonar.projectDescription</code></td><td><code>description</code></td></tr><tr><td><code>sonar.links.homepage</code></td><td><code>homepage</code></td></tr><tr><td><code>sonar.links.issue</code></td><td><code>bugs.url</code></td></tr><tr><td><code>sonar.links.scm</code></td><td><code>repository.url</code></td></tr></tbody></table>

In addition, specific values may be added to the parameters listed below if particular conditions are fulfilled.

<table><thead><tr><th width="298">Analysis parameter</th><th>Value(s) added to</th><th>Conditions</th></tr></thead><tbody><tr><td><code>sonar.exclusions</code><br><code>sonar.javascript.lcov.reportPaths</code></td><td><code>nyc.report-dir</code> and <code>jest.converageDirectory</code> directories</td><td>If an <code>lcov.info</code> file is specified in the <code>package.json</code> fields <code>nyc.report-dir</code> and <code>jest.converageDirectory</code></td></tr><tr><td><code>sonar.testExecutionReportPath</code></td><td><code>Xunit.xml</code> file</td><td>If the <code>package.json</code> has declared the dependency <code>mocha-sonarqube-reporter</code> and the file <code>xunit.xml</code> exists in the project directory.</td></tr></tbody></table>

## Providing analysis parameters through the scanner API <a href="#provide-param-through-scanner-api" id="provide-param-through-scanner-api"></a>

See [#add-to-build-files](https://docs.sonarsource.com/sonarqube-cloud/analyzing-source-code/scanners/using#add-to-build-files "mention") or [#npx](https://docs.sonarsource.com/sonarqube-cloud/analyzing-source-code/scanners/using#npx "mention") articles.

## Setting analysis parameters in environment variables <a href="#environment-variables" id="environment-variables"></a>

You can use environment variables on the CI/CD host to define analysis parameters:

* Some parameters can be defined through a dedicated environment variable. For example, the `sonar.region` property value can be defined through the `SONAR_REGION` environment variable. See [parameters-not-settable-in-ui](https://docs.sonarsource.com/sonarqube-cloud/analyzing-source-code/analysis-parameters/parameters-not-settable-in-ui "mention")to know which parameters can be set as environment variables.
* The `SONAR_SCANNER_JSON_PARAMS` environment variable allows you to pass multiple analysis parameters in a single variable, encoded as JSON.

Example:

```json
SONAR_SCANNER_JSON_PARAMS = { "sonar.region":"us",  "sonar.verbose:"true"}  
```

{% hint style="info" %}
Parameters set through their respective environment variable (e.g. `SONAR_REGION`) have precedence over parameters set through `SONAR_SCANNER_JSON_PARAMS`.
{% endhint %}

## Setting analysis parameters in sonar-project.properties <a href="#sonar-project-properties-file" id="sonar-project-properties-file"></a>

See the [#use](https://docs.sonarsource.com/sonarqube-cloud/analyzing-source-code/sonarscanner-cli#use "mention") article on the [sonarscanner-cli](https://docs.sonarsource.com/sonarqube-cloud/analyzing-source-code/scanners/sonarscanner-cli "mention") page.

## Setting analysis parameters in the SonarQube Cloud UI <a href="#in-user-interface" id="in-user-interface"></a>

You can set analysis parameters in the SonarQube Cloud UI for your project provided you have Administer permission for this project.

To set analysis parameters at the project level:

1. Open your project. See [retrieving-projects](https://docs.sonarsource.com/sonarqube-cloud/managing-your-projects/retrieving-projects "mention") for details.
2. Go to **Administration** > **General Settings**.

## Related pages

* Choosing your region \[LINK]
* [using](https://docs.sonarsource.com/sonarqube-cloud/analyzing-source-code/scanners/sonarscanner-for-npm/using "mention")
* [parameters-not-settable-in-ui](https://docs.sonarsource.com/sonarqube-cloud/analyzing-source-code/analysis-parameters/parameters-not-settable-in-ui "mention")
* [test-coverage-parameters](https://docs.sonarsource.com/sonarqube-cloud/analyzing-source-code/test-coverage/test-coverage-parameters "mention")
* [test-execution-parameters](https://docs.sonarsource.com/sonarqube-cloud/analyzing-source-code/test-coverage/test-execution-parameters "mention")
