New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

usb

Package Overview
Dependencies
Maintainers
3
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

usb

Library to access USB devices

2.15.0
latest
Source
npm
Version published
Weekly downloads
162K
-0.85%
Maintainers
3
Weekly downloads
 
Created

What is usb?

The 'usb' npm package provides a way to interact with USB devices in Node.js. It allows you to list, read from, and write to USB devices, making it useful for applications that need to communicate with hardware peripherals.

What are usb's main functionalities?

Listing USB Devices

This feature allows you to list all USB devices connected to the system. The code sample demonstrates how to use the 'usb' package to retrieve and print the list of connected USB devices.

const usb = require('usb');
const devices = usb.getDeviceList();
console.log(devices);

Opening a USB Device

This feature allows you to open a connection to a specific USB device using its vendor and product IDs. The code sample shows how to find and open a USB device.

const usb = require('usb');
const device = usb.findByIds(vendorId, productId);
device.open();

Reading from a USB Device

This feature allows you to read data from a USB device. The code sample demonstrates how to open a device, access its endpoint, and read data from it.

const usb = require('usb');
const device = usb.findByIds(vendorId, productId);
device.open();
const endpoint = device.interfaces[0].endpoints[0];
endpoint.transfer(64, (error, data) => {
  if (error) {
    console.error(error);
  } else {
    console.log(data);
  }
});

Writing to a USB Device

This feature allows you to write data to a USB device. The code sample shows how to open a device, access its endpoint, and send data to it.

const usb = require('usb');
const device = usb.findByIds(vendorId, productId);
device.open();
const endpoint = device.interfaces[0].endpoints[1];
const data = Buffer.from('Hello USB');
endpoint.transfer(data, (error) => {
  if (error) {
    console.error(error);
  } else {
    console.log('Data sent');
  }
});

Other packages similar to usb

Keywords

usb

FAQs

Package last updated on 21 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts