> ## Documentation Index
> Fetch the complete documentation index at: https://docs.germainux.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.js Error and Exception Monitoring

> How to collect Node.js errors and unhandled exceptions with GermainUX, including when your application already listens for uncaught exceptions.

Components
[`Code Profiler`](https://docs.germainux.com/main/germain-ux-code-profiler)

Availability
8.6.0 or later

> [!NOTE]
>
> This monitoring can collect all types of custom and standard errors (`AssertionError, EvalError, SyntaxError, RangeError, ReferenceError, TypeError, URIError`) and all system errors including:

> [card] [System Errors](#system-errors)
>
> Unhandled process-level failures

> [card] [Configuration](#configuration)
>
> Enabling exception monitoring

> [card] [Handled exceptions](#handled-exceptions)
>
> Reporting caught errors manually

> [card] [Warning Monitoring](#warning-monitoring)
>
> Bugs and security warnings

## System Errors

| Error | Details |
| - | - |
| Permission denied |   |
| Address already in use |   |
| Connection refused |   |
| Connection reset by peer |   |
| File exists |   |
| Is a directory |   |
| Too many open files in system |   |
| No such file or directory |   |
| Not a directory |   |
| Directory not empty |   |
| Operation not permitted |   |
| Broken pipe |   |
| Operation timed out |   |

## Configuration

```javascript theme={null}
const config = GermainAPM.getDefaultConfiguration('http://GERMAIN_APM_SERVER/');
config.monitoring.unhandledExceptions.enabled = true;           // Enable/Disable automatic unhandled exception monitoring. Default: true.
config.monitoring.unhandledExceptions.exitOnError = true;       // Process exit on unhandled exception (with exit code 1). Default: true.
config.monitoring.unhandledExceptions.callbackOnError = null;   // Callback on unhandled exception provided as a function if exitOnError=false. Callback function will receive Error instance as the only parameter. Default: empty / no callback.
```

## ‼ **Unhandled exceptions**

### Caught by process

If you already catching all unhandled exceptions by listening to the `uncaughtException` event on the `process` then you should explicitly collect the exception in your exception handler like this and disable `config.monitoring.unhandledExceptions`:

```javascript theme={null}
process.on('uncaughtException', function (err) {
    GermainAPM.collectError(err);
});
```

### Uncaught by process

If you don't catch unhandled exceptions yet, you have 2 options to use our monitoring to catch them:

#### Exit on Error

If you set the `exitOnError:true` then, once the exception caught, we will exit from the process with id 1 (`process.exit(1)`). Node.js does recommend to exit from the process following an unhandled exception.

Correct configuration for this scenario:

```javascript theme={null}
const config = GermainAPM.getDefaultConfiguration('http://GERMAIN_APM_SERVER/');
config.monitoring.unhandledExceptions.enabled = true;
config.monitoring.unhandledExceptions.exitOnError = true;
config.monitoring.unhandledExceptions.callbackOnError = null;
```

#### Callback on Error

If you set the `exitOnError:false` but provide a function callback to the `callbackOnError` then, once the exception is caught, we will execute your callback by passing the Error instance as the only parameter. Node.js doesn't recommend to proceed with any logic if an unhandled exception occurs.

Correct configuration for this scenario:

```javascript theme={null}
const config = GermainAPM.getDefaultConfiguration('http://GERMAIN_APM_SERVER/');
config.monitoring.unhandledExceptions.enabled = true;
config.monitoring.unhandledExceptions.exitOnError = false;
config.monitoring.unhandledExceptions.callbackOnError = function(error){
  // your logic to process the exception
};
```

### Disable automatic unhandled exceptions monitoring

You can disable this monitoring through `GermainAPMConfiguration`:

```javascript theme={null}
const config = GermainAPM.getDefaultConfiguration('http://GERMAIN_APM_SERVER/');
config.monitoring.unhandledExceptions.enabled = false;
```

## Handled exceptions

You can collect an exception / an error explicitly by adding the following code to your handled exception logic:

```javascript theme={null}
try {
   // ...
} catch(err){
   GermainAPM.collectError(err);
   // your logic here ...
}
```

## Warning Monitoring

By default GermainUX monitors Node.js warnings (bad coding practices, bugs, or security vulnerabilities). You can disable this monitoring through `GermainAPMConfiguration`:

```javascript theme={null}
const config = GermainAPM.getDefaultConfiguration('http://GERMAIN_APM_SERVER/');
config.monitoring.warning = false;
```

## Get Help

> [card] [Contact GermainUX Support](https://docs.germainux.com/main/support.md)
>
> The GermainUX team helps you get up and running faster, empower your team, turn data into actionable insights, and optimize performance to deliver measurable business outcomes.

> [card] Can't find what you need?
>
> Search all GermainUX docs with **Ctrl + K**, or use the feedback buttons at the bottom of this page to tell us what is missing.

The content of this document is proprietary to GERMAIN SOFTWARE.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.