Skip to content

Instantly share code, notes, and snippets.

@sudipp
Created January 15, 2019 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudipp/2bd654432bb477eec819701a5d3198dc to your computer and use it in GitHub Desktop.
Save sudipp/2bd654432bb477eec819701a5d3198dc to your computer and use it in GitHub Desktop.
usb-drive-util-test.js
const drives = require('../src/drives').Drives;
function loadUSBDrvList(){
drives.loadUSBDriveDetails().then(function(result){
if(result && result.length== 0){
console.log('No USB drive found in the system');
return;
}
console.log('Loading USB drive(s) details');
_.forEach(result, function (driveStats){
console.log(driveStats);
})
}).catch(function(err) {
console.log(err.message);
});
}
loadUSBDrvList();
let drv = new drives();
//Track events when drive is attached and removed
drv.on("usbadd",(device)=>{
console.log('An USB drive is attached to system');
setTimeout(function() {
loadUSBDrvList();
}, 1000);
})
.on("usbremove", (device)=>{
console.log('drive removed');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment