Install with npm:
$ npm install --save is-installed
Why use this?
- Useful for setup in unit tests, to conditionally install packages that aren't already installed.
- Useful for validating that a global CLI is installed, and that it satisfies a valid semver range (like gulp-cli etc)
var isInstalled = require('is-installed');
console.log(isInstalled('foo'));
//=> false
Returns true if npm package name
is installed in node_modules
relative to the user's current working directory.
Params
name
{String}: The name of the module to look for.cwd
{String|Function}: Optionally specify a directory to start the search from, or a validation function.validate
{Function}: Optionally specify a validation function to use as the last argument.returns
{Boolean}
Example
isInstalled('gulp');
// or with a validation function
var semver = require('semver');
var installed = isInstalled('gulp', function(pkg) {
return semver.gt(pkg.version, '0.1.0');
});
Returns true if npm package name
is installed in node_modules
in the global npm directory.
Params
name
{String}: The name of the module to look for.cwd
{String|Function}: Optionally specify a directory to start the search from, or a validation function.validate
{Function}: Optionally specify a validation function to use as the last argument.returns
{Boolean}
Example
isInstalled.global('gulp-cli');
// or with a validation function
var semver = require('semver');
var installed = isInstalled.global('gulp-cli', function(pkg) {
return semver.gt(pkg.version, '0.1.0');
});