> For the complete documentation index, see [llms.txt](https://docs-v2.hypertest.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-v2.hypertest.co/setup-guide/start-a-test-run/start-a-test-run.md).

# Node

## Prerequisites

### 1. Install/update ht-cli npm package

<pre class="language-bash"><code class="lang-bash"><strong>npm install -g @hypertestco/ht-cli --save-exact
</strong></code></pre>

Verify htcli has been installed using the below command:

```bash
htcli --help
```

## Getting Started:

### 1. Create a Test Configuration File

Available Configurations:

{% code title=".htTestConf.js" fullWidth="false" %}

```javascript
const requestTypes = {
  HTTP: 'HTTP',
  GRAPHQL: 'GRAPHQL',
  KAFKA: 'KAFKA',
  GRPC: 'GRPC',
  AMQP: 'AMQP',
};

module.exports = {
  htBackendBaseUrl: "", // URL of HyperTest server (Required)
  serviceIdentifier: "", // UUID for the service (Required)
  requestTypesToTest: [requestTypes.HTTP], // What kind of requests to include in the test
  httpCandidateUrl: "", // HTTP URL of App under test (Optional)
  // graphqlCandidateUrl: "", // GraphQL URL of App under test (Optional)
  appStartCommand: process.platform === 'win32' ? 'npm.cmd' : 'npm', // Command to start the app (Required)
  appStartCommandArgs: ["run", "start-app-with-nyc"],  // App start command arguments (Required)
  appWorkingDirectory: __dirname, // Working directory for the app (default: current working dir) (Optional)
  appStartTimeoutSec: 90, // Timeout in seconds for the start command (default: 10) (Optional)
  testBatchSize: 50, // Number of concurrent test requests (default: 50) (Optional)
  //testRequestsLimit": 10, // Number requests to test (Optional)
  //httpReqFiltersArr: [], // "<GET /users>", "<ANY REGEX:^/payments>" (Optional)
  htExtraHeaders: { // Object containing additional headers for HyperTest server requests (Optional)
    // authorization: 'Basic ' + Buffer.from('USERNAME:PASSWORD').toString('base64')
  },
  // httpReqsToTest: [], // specific http requests to be tested can be mentioned. Request Id can be taken from "All Requests" page in dashboard.
  // graphqlReqsToTest: [], // specific graphql requests to be tested can be mentioned.
  // grpcReqsToTest: [], // specific grpc requests to be tested can be mentioned.
  // kafkaReqsToTest: [], // specific kafka requests to be tested can be mentioned.
  // amqpReqsToTest: [], // specific amqp requests to be tested can be mentioned.
  // tags: [{name: '', value: ''}], // requests which contain the mentioned tags will be tested. Refer Tags under "User Guides/Node.js SDK" for more information.
  
  // exitCodeSetter({ testResult }) {
  //  console.log('==test results==')
  //  console.log(testResult)
  //  return 0;
  //},
 
  // exclusionStringsForDifferences: [], // e.g., ['01\.02\.03\.04', 'HyPeRtEsT'],
  // reservedAppPorts: [], // Ports used by the host application e.g., [3001,4001]
};
```

{% endcode %}

Please refer this [link](/user-guides/node.js-sdk/type-references.md) for param type references in filterFunctionToIgnoreMockDiffs and filterFunctionToIgnoreResponseDiffs.

### 2. CLI token generation

Please follow this [link](/user-guides/node.js-sdk/cli-login.md#id-1-if-running-test-in-ci) to complete token generation if test is being run in CI env.

Please follow this [link](/user-guides/node.js-sdk/cli-login.md#id-2-if-running-test-on-local) to complete CLI login if test is being run in local.

### 3. Start new test

Start a new test by running this command.

```
htcli start-new-test --config-file-path ./.htTestConf.js
```

Open the help to list all possible options available

```
htcli start-new-test --help
```

### 4. Update HT Packages

The following command updates the ht-cli and node-sdk packages to the latest deployed backend version. Please refer this [link](/user-guides/node.js-sdk/update-ht-cli-and-node-sdk.md) for addtional details.

```
htcli update-ht-packages --package-manager <package manager name> --config-file-path <path-to-your-cli-config>
```

### 5. Update Code Coverage

The following command saves the code coverage of your application's requests on the latest master branch to the hypertest backend. Please refer this [link](/user-guides/node.js-sdk/code-coverage-based-features/updating-test-coverage.md) for additional details.

```
htcli update-coverage --config-file-path <path-to-your-cli-config>
```

### 6. Adding Hypertest CLI commands as scripts to your app's package.json

The best way to utilize the CLI commands is to add them as scripts in your package.json and use them flexibly in your CI and local env's.

<pre><code>// App's package.json
{
    "scripts" : {
<strong>        "run-test": "htcli start-new-test --config-file-path ./.htConf.js",
</strong>        "update-ht-packages" : "htcli update-ht-packages --package-manager &#x3C;package manager name> --config-file-path ./.htConf.js",
        "update-cov": "htcli update-coverage --config-file-path ./.htConf.js"
    }, 
}
</code></pre>

### 7. Test reports

After the test is completed. You can see the results on the dashboard under Test Results

<figure><img src="https://2702123086-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKGOAD6xy07C4jYV7QqmF%2Fuploads%2FNdfl6ovj49TmtYLaellO%2FScreenshot%20from%202023-09-04%2020-41-16.png?alt=media&amp;token=2b21d91c-3d91-40b2-a415-6d1dc1ae1034" alt=""><figcaption></figcaption></figure>
