Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
The hasbin npm package is used to check if a specific binary is available in the system's PATH. This can be useful for ensuring that required dependencies are installed before running a script or application.
Check if a binary exists
This feature allows you to check if a specific binary, such as 'node', exists in the system's PATH. The callback function receives a boolean indicating the presence of the binary.
const hasbin = require('hasbin');
hasbin('node', function(result) {
if (result) {
console.log('Node.js is installed');
} else {
console.log('Node.js is not installed');
}
});
Check multiple binaries
This feature allows you to check the existence of multiple binaries in the system's PATH. It iterates over an array of binary names and checks each one, logging the result.
const hasbin = require('hasbin');
const binaries = ['node', 'npm', 'git'];
binaries.forEach(bin => {
hasbin(bin, function(result) {
console.log(`${bin} is ${result ? '' : 'not '}installed`);
});
});
The 'which' package is used to locate a command in the system's PATH. It is similar to hasbin but provides more detailed information about the location of the binary. It can be used to find the full path of a binary, whereas hasbin only checks for its existence.
The 'command-exists' package checks if a command-line command exists. It is similar to hasbin in that it checks for the presence of a binary, but it also provides a promise-based API in addition to the callback-based API.
The 'execa' package is used for executing shell commands in Node.js. While its primary purpose is not to check for the existence of binaries, it can be used to run commands and check their output, thus indirectly verifying the presence of a binary. It offers more advanced features for command execution compared to hasbin.
Check whether a binary exists in the PATH
environment variable.
var hasbin = require('hasbin');
// Check if a binary exists
hasbin('node', function (result) {
// result === true
});
hasbin('wtf', function (result) {
// result === false
});
// Check if all binaries exist
hasbin.all(['node', 'npm'], function (result) {
// result === true
});
// Check if at least one binary exists
hasbin.some(['node', 'wtf'], function (result) {
// result === true
});
// Find the first available binary
hasbin.first(['node', 'npm'], function (result) {
// result === 'node'
});
Install HasBin with npm:
npm install hasbin
hasbin(binaryName, callback)
Check whether a binary exists on one of the paths in process.env.PATH
. Calls back with true
if it does.
// Arguments
binaryName = String
callback = Function(Boolean)
// Example
hasbin('node', function (result) {
// result === true
});
hasbin.sync(binaryName)
Synchronous hasbin
.
// Arguments
binaryName = String
return Boolean
// Example
result = hasbin.sync('node');
hasbin.all(binaryNames, callback)
Check whether all of a set of binaries exist on one of the paths in process.env.PATH
. Calls back with true
if all of the binaries do. Aliased as hasbin.every
.
// Arguments
binaryNames = Array(String)
callback = Function(Boolean)
// Example
hasbin.all(['node', 'npm'], function (result) {
// result === true
});
hasbin.all.sync(binaryNames)
Synchronous hasbin.all
. Aliased as hasbin.every.sync
.
// Arguments
binaryNames = Array(String)
return Boolean
// Example
result = hasbin.all.sync(['node', 'npm']);
hasbin.some(binaryNames, callback)
Check whether at least one of a set of binaries exists on one of the paths in process.env.PATH
. Calls back with true
if at least one of the binaries does. Aliased as hasbin.any
.
// Arguments
binaryNames = Array(String)
callback = Function(Boolean)
// Example
hasbin.some(['node', 'npm'], function (result) {
// result === true
});
hasbin.some.sync(binaryNames)
Synchronous hasbin.some
. Aliased as hasbin.any.sync
.
// Arguments
binaryNames = Array(String)
return Boolean
// Example
result = hasbin.some.sync(['node', 'npm']);
hasbin.first(binaryNames, callback)
Checks the list of binaryNames
to find the first binary that exists on one of the paths in process.env.PATH
. Calls back with the name of the first matched binary if one exists and false
otherwise.
// Arguments
binaryNames = Array(String)
callback = Function(String|false)
// Example
hasbin.first(['node', 'npm'], function (result) {
// result === 'node'
});
hasbin.first.sync(binaryNames)
Synchronous hasbin.first
.
// Arguments
binaryNames = Array(String)
return String|false
// Example
result = hasbin.first.sync(['node', 'npm']);
To contribute to HasBin, clone this repo locally and commit your code on a separate branch.
Please write unit tests for your code, and check that everything works by running the following before opening a pull-request:
make ci
HasBin is licensed under the MIT license.
Copyright © 2015, Springer Nature
1.2.3 (2016-05-27)
FAQs
Check whether a binary exists in the PATH environment variable
The npm package hasbin receives a total of 167,817 weekly downloads. As such, hasbin popularity was classified as popular.
We found that hasbin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.