Reputation: 1415
I'm new with node.js, actually I'm playing with Electron. My app is for configuring device from specific vendor and to read recorded files.
Config is a text file in device root. Recorded files in folder.
I want to know when new device connected and disconnected with mount points.
I can do this tasks (detect and list mount points) separately but can't figure out how to glue it.
To have callback on attach/detach I use node-usb
module and
var usb = require('usb');
usb.on('attach', ...);
But there is no mount points, example of output:
{ busNumber: 253,
deviceAddress: 3,
deviceDescriptor:
{ bLength: 18,
bDescriptorType: 1,
bcdUSB: 528,
bDeviceClass: 0,
bDeviceSubClass: 0,
bDeviceProtocol: 0,
bMaxPacketSize0: 64,
idVendor: 34148,
idProduct: 4096,
bcdDevice: 4352,
iManufacturer: 1,
iProduct: 2,
iSerialNumber: 3,
bNumConfigurations: 1 },
portNumbers: [] }
My targeted platforms OS X and Windows. Only way I see is to build native module on C++.
Is there a simple way to achieve this task?
Upvotes: 5
Views: 1886
Reputation: 5380
drivelist is a node package to handle mounted volumes: https://github.com/resin-io-modules/drivelist
What you can do is to add it as a dependency and call drivelist.list()
in an interval, compare the difference of the results of the previous run to the current run to get a list of added or removed volumes.
It supports Windows, macOS and Linux.
Upvotes: 1