Access devices over MTP using Node.js
On some operating systems (e.g. macOS) devices like modern Android phones do not mount as disk drives without using external software, like Android File Transfer or OSXFUSE.
node-mtp allows Node.js (v10 or higher) and Electron apps (v3.0.0 or higher) to read files from devices over MTP without requiring additional software or drivers.
node-mtp is an N-API wrapper around the libmtp library. It uses version 3 of N-API which is only available on Node v10 and higher.
const mtp = require('node-mtp'); mtp.attach(); const list = mtp.getFileListing(); console.log('Files:', list); mtp.getFile(8, 'test.jpg'); // <file id>, <destination> mtp.release();
To build this on your own machine, you'll need
sudo apt-get install libmtp-dev
brew install libmtp
Updating on Yarn/NPM
The following steps will update the module on Yarn/NPM:
git push && git push --tags
- Wait for Travis to finish.
- Download the releases from Github:
Note that you need to
yarn global add prebuildify-ci to get the prebuilds.