
Security News
minimatch Patches 3 High-Severity ReDoS Vulnerabilities
minimatch patched three high-severity ReDoS vulnerabilities that can stall the Node.js event loop, and Socket has released free certified patches.
install-if-needed
Advanced tools
Installs the given list of modules and saves them into their respective fields in your nearest package.json. Dependencies that already exist in your package.json will be skipped.
var install = require('install-if-needed')
install({
dependencies: ['through2'],
devDependencies: ['tape@2.x', 'standard']
}, function(err) {
if (err)
console.error("There was an error installing.")
})
You can pass { stdio: 'inherit' } to preserve logging and colors, acting like the usual npm install command.
install(opt[, cb])Looks at package JSON and installs any of the specified dependencies that are not listed in their respective field.
cwd the directory for the closest package.json, (default process.cwd())package optional package data, if not defined will search for closest package.jsonsave whether to --save, --save-dev and --save-optional (default true)dependencies dependencies to installdevDependencies dev dependencies to installoptionalDependencies optional dependencies to installcommand the command to spawn when installing, defaults to 'npm'Other options are passed to spawn-npm-install.
On complete, cb is called with (err) status. All dependencies also accept a single string instead of an array.
Alternatively, opt can be a string or array, which is the same as listing it in dependencies.
//e.g.
// npm install tape --save
install('tape', done)
This helps build CLI tooling that auto-installs modules as needed. For example, a tool which stubs out an empty test file for tape:
#!/usr/bin/env node
var install = require('install-if-needed')
var fs = require('fs')
var template = fs.readFileSync(__dirname + '/template.js')
install({
devDependencies: 'tape'
}, function(err) {
if (err) throw err
fs.writeFile(process.argv[2], template)
})
And the CLI might be as simple as:
quick-tape tests/simple.js
MIT, see LICENSE.md for details.
FAQs
installs the given modules if needed
We found that install-if-needed demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.

Security News
minimatch patched three high-severity ReDoS vulnerabilities that can stall the Node.js event loop, and Socket has released free certified patches.

Research
/Security News
Socket uncovered 26 malicious npm packages tied to North Korea's Contagious Interview campaign, retrieving a live 9-module infostealer and RAT from the adversary's C2.

Research
An impersonated golang.org/x/crypto clone exfiltrates passwords, executes a remote shell stager, and delivers a Rekoobe backdoor on Linux.