---
title: usbhotplug
slug: develop/usbhotplug
docTags: 
createdAt: 2025-03-27T16:58:57.890Z
---

The *usbhotplug* object can be used to generate events when USB devices are added or removed. 

**usbhotplug IDL**

```javascript
interface usbhotplugevent {
    attribute String action;    // "add", "remove"
    attribute String path;      // platform specific device path
};

callback UsbHotplugEventCallback = void (usbhotplugevent event);

interface UsbHotplug {
    void addEventListener(String type, UsbHotplugEventCallback callback);
    void removeEventListener(String type, UsbHotplugEventCallback callback);
};

```

## Event Creation

To create a *usbhotplug* event, load the *@brightsign/usbhotplug* module using the `require()` method:

```javascript
let usbhotplugClass = require("@brightsign/usbhotplug");
let usbhotplug = new usbhotplugClass();
```

## UsbHotPlug 

Use this interface to configure a *usbhotplug* event.

- `usbhotplugevent`: This event is raised when the hotplug status changes. Use the `addEventListener()` method to listen for this event, or the `removeEventListener()` method to remove an event listener.

## usbhotplugevent Properties 

- `action` <font color="#6554c0">string</font>: Indicates whether a USB device has been added or removed.
- `path` <font color="#6554c0">string</font>: The path is an arbitrary string which varies between models and should not be parsed.  It may be useful for diagnostics. The path will be the same for add and remove events for a particular USB device. Use `@brightsign/deviceinfo` `getUsbBusTopology()` to examine attached devices. These events are hints that the topology has changed.

## Example

```javascript
let usbhotplugClass = require("@brightsign/usbhotplug");
let usbhotplug = new usbhotplugClass();

function onusbhotplugevent(event) {
  if (event.action == 'add') {
     console.log('New device at' + event.path)
  } else if (event.action == 'remove')
  {
     console.log('Device removed from' + event.path)
  }
}

usbhotplug.addEventListener("usbhotplugevent", onusbhotplugevent);
```

