Detect USB and get mount points/paths
const usbEvents = require('detect-usb');
// To start listening
usbEvents.startListening();
// To get list of connected USBs
(async () => {
console.log(await usbEvents.getUSBList());
})();
usbEvents.on('insert', (data) => {
console.log(data);
})
usbEvents.on('eject', (data) => {
console.log(data);
})
// To stop listening
usbEvents.stopListening();
{
event: 'insert',
data:
{
key: '/media/test/sss',
name: 'sss',
devicepath: '/dev/sda',
isAccessible: true
}
}
{ event: 'eject', data: { key: '/media/test/sss' } }
- Verified on Windows & Linux
- Uses usb-detection & drivelist