Automated module to fetch all your 3rd party binaries to power your nodejs applications
npm install get-binaryThis module is used to fetch and extract binaries required for your apps, where no supported binaries are found to be installed or previously downloaded.
First install yarn add get-binary;
Then start the process by passing the correct options to determine the right binary for each Operating system.
``javascript
const getB = require('get-binary');
const requiredBinaries = [
{
// required
name: 'FFMPEG',
// the os variant to target
os: {
platform: 'linux',
arch: 'x64',
},
// remote URL to get binary from
remote: {
url: 'https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v3.2/ffplay-3.2.2-linux-64.zip',
},
// Local values
local: {
// the command to run in order to check if the binary is already installed
// this is run using the "which" command
whichCmd: ['ffmpeg'],
// directory to save the binary
dir: '/path/to/save/binaries',
// name of the binary
name: 'ffmpeg',
},
},
{
name: 'FFMPEG',
os: {
platform: 'windows',
arch: 'x64',
},
remote: {
url: 'https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.2.1/ffplay-4.2.1-win-64.zip',
},
local: {
whichCmd: ['ffmpeg'],
dir: '/path/to/save/binaries',
name: 'ffmpeg',
},
},
//{...other os variants or binaries}
];
// now get the binaries
getB.get(requiredBinaries)
.then((fetchedBinaries) => {
// all binaries fetched....
console.log(fetchedBinaries);
})
.catch(console.error);
`
- The array of required binaries is filtered using platform and arch values returned by the os module..os
- If the key is missing, then the binary is assumed to match all operating systems. Omitting this key is the way to deal with cross-platform binaries.whichCmd
- Every matched binary is downloaded if:
- The is missing or when run using which, does not find any installed binaries and...local.dir/local.name
- ...no downloaded binary is found at the path given by
- An array of all binaries already existing, or freshly downloaded is returned...
In the example above, the following binaries are returned for my case:
`javascript`
{
binaries: { FFMPEG: [ '/usr/bin/ffmpeg' ] },
errors: []
}
This is because I already have ffmpeg installed and the which command returns the installation path.
Otherwise, the binary would have been downloaded, unzipped and the path to the freshly unzipped files returned.
Returns an object of binaries (already installed or downloaded) as indicated for that operating system, and an array or all errors encountered.
This argument should be an array containing details for each binary to be installed on the specific operating system.#### Binary Details
| Property | Description | Required |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| name |
String
The name of the binary. It is also the name of the binary returned.
Example: {FFMPEG:['/usr/bin/ffmpeg']} where FFMPEG was the name entered. | Yes |
| os | Object
Holds details about the operating system that the binary is intended for. This Object should contain platform and arch keys.
Example: {platform:'windows',arch:'x64'} | No |
| remote | Object
Details of where to download the binary from. The object must have a url key which must be a valid URL. | Yes |
| local| Object
Details of where to download the binary to. The object must contain a dir and name. Values of dir and name must combine (using path.join()) to form a valid path on your machine or else creating binary directories will fail. | Yes |$3
Type: Boolean
If true, then a new binary is always downloaded irrespective of whether whichCmd` finds an installed binary or one was previously downloaded. If a binary had already been downloaded, then all files will be replaced.This option is useful if you want to force you app to download the latest binaries.
Have a look at this Test File for a good example on how to get multiple binaries across different platforms.