> For the complete documentation index, see [llms.txt](https://docs.viesus.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.viesus.com/reference/node.js-module/api-reference.md).

# API Reference

{% hint style="info" %}
**Linux Only**

The VIESUS Node.js module is available on **Linux only**.
{% endhint %}

***

## Import

```js
const viesus = require('viesus');
```

***

## `new viesus.MyViesusObject(guid)`

Creates and initializes a VIESUS enhancer instance. Create one object per worker thread and **reuse it** across multiple `Enhance()` calls — initialization is expensive.

| Parameter | Type     | Description              |
| --------- | -------- | ------------------------ |
| `guid`    | `string` | Your VIESUS license GUID |

```js
const viesusObj = new viesus.MyViesusObject('4e8f35ab-7f72-4b1e-a1fd-2b5e9c58e9d3');
```

***

## `viesusObj.Enhance(fromPath, toPath, iniPath, resPath)`

Enhances a single image. **Synchronous** — must be called from a worker thread, not the main thread.

<table><thead><tr><th width="129">Parameter</th><th width="109.800048828125">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>fromPath</code></td><td><code>string</code></td><td>Absolute path to the input image</td></tr><tr><td><code>toPath</code></td><td><code>string</code></td><td>Absolute path for the enhanced output image</td></tr><tr><td><code>iniPath</code></td><td><code>string</code></td><td>Absolute path to the <code>viesusini.json</code> configuration file</td></tr><tr><td><code>resPath</code></td><td><code>string</code></td><td>Absolute path for the result JSON output file</td></tr></tbody></table>

**Returns:** `number`

* `> 0` — success; value is processing time in milliseconds
* `< 0` — error; see [error codes](#error-codes)

```js
const result = viesusObj.Enhance(fromPath, toPath, iniPath, resPath);
if (result > 0) {
  console.log(`Enhanced in ${result}ms`);
} else {
  console.error(`Error: ${result}`);
}
```

***

## Error codes

<table><thead><tr><th width="154">Code</th><th>Description</th></tr></thead><tbody><tr><td><code>-1</code></td><td>Init failed</td></tr><tr><td><code>-2</code></td><td>GUID wrong</td></tr><tr><td><code>-3</code></td><td>Internal error</td></tr><tr><td><code>-4</code></td><td>Loading image not possible</td></tr><tr><td><code>-5</code></td><td>Can't open file</td></tr><tr><td><code>-6</code></td><td>File not found</td></tr><tr><td><code>-7</code></td><td>File is empty</td></tr><tr><td><code>-8</code></td><td>Memory open internal error</td></tr><tr><td><code>-9</code></td><td>Enhancement failed — contact <a href="mailto:info@viesus.com">info@viesus.com</a></td></tr><tr><td><code>-10</code></td><td>Parameter file not found</td></tr><tr><td><code>-11</code></td><td>Parameter file empty</td></tr><tr><td><code>-12</code></td><td>Output format not supported</td></tr><tr><td><code>-13</code></td><td>Error writing result file</td></tr><tr><td><code>-126</code></td><td>Enhancement failed — image was already enhanced</td></tr><tr><td><code>-378</code></td><td>Wrong GUID</td></tr><tr><td><code>&#x3C; -18</code></td><td>Internal error — contact <a href="mailto:info@viesus.com">info@viesus.com</a></td></tr></tbody></table>

***

## Result JSON

When `WriteResultFiles: 1` is set in `viesusini.json`, a JSON file is written to `resPath` after each enhancement with per-image processing details:

```json
{
  "brightCorrStrength": 0.011,
  "colorCorrStrength": 0.083,
  "contrCorrStrength": 0.0,
  "fdApplied": 1,
  "ggaApplied": 0,
  "globShpApplied": 0,
  "glowStrength": 0.0,
  "ieApplied": 1,
  "isArtificial": 0,
  "isMonochrome": 0,
  "locShpApplied": 1,
  "noiseStrength": 0.0,
  "nrApplied": 0,
  "rerApplied": 1,
  "rszApplied": 1,
  "rszSRApplied": 0,
  "arApplied": 0,
  "bgApplied": 0,
  "staApplied": 0
}
```

<table><thead><tr><th width="202.5999755859375">Field</th><th width="84.7999267578125">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>brightCorrStrength</code></td><td>float</td><td>Applied brightness correction strength</td></tr><tr><td><code>colorCorrStrength</code></td><td>float</td><td>Applied color correction strength</td></tr><tr><td><code>fdApplied</code></td><td>int</td><td><code>1</code> if face detection ran</td></tr><tr><td><code>ieApplied</code></td><td>int</td><td><code>1</code> if image enhancement ran</td></tr><tr><td><code>isArtificial</code></td><td>int</td><td><code>1</code> if image was classified as artificial/synthetic</td></tr><tr><td><code>isMonochrome</code></td><td>int</td><td><code>1</code> if image was detected as monochrome</td></tr><tr><td><code>locShpApplied</code></td><td>int</td><td><code>1</code> if local sharpening was applied</td></tr><tr><td><code>rszApplied</code></td><td>int</td><td><code>1</code> if resizing was applied</td></tr><tr><td><code>rszSRApplied</code></td><td>int</td><td><code>1</code> if AI upscaling was used for resize</td></tr><tr><td><code>arApplied</code></td><td>int</td><td><code>1</code> if artifact removal was applied</td></tr><tr><td><code>bgApplied</code></td><td>int</td><td><code>1</code> if background handling was applied</td></tr></tbody></table>

***

## Thread pool pattern

The recommended production pattern uses `node-worker-threads-pool`:

```js
// worker.js
const { parentPort, workerData } = require('worker_threads');
const viesus = require('viesus');

const viesusObj = new viesus.MyViesusObject(workerData);

parentPort.on('message', (job) => {
  const result = viesusObj.Enhance(job.fromPath, job.toPath, job.iniPath, job.resPath);
  parentPort.postMessage(result);
});
```

```js
// main.js
const { StaticPool } = require('node-worker-threads-pool');

const pool = new StaticPool({
  size: Number(process.env.UV_THREADPOOL_SIZE),
  task: './worker.js',
  workerData: 'YOUR-GUID-HERE'
});

async function enhanceImage(fromPath, toPath, iniPath, resPath) {
  const result = await pool.exec({ fromPath, toPath, iniPath, resPath });
  if (result < 0) throw new Error(`VIESUS error: ${result}`);
  return result;
}
```

See [Getting Started](/reference/node.js-module/getting-started.md) for the complete example.


---

# 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.viesus.com/reference/node.js-module/api-reference.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.
