API Reference (Programmatic Usage)
npm-check-updates
can be imported and used as a module in your own Node.js scripts, providing a powerful way to automate dependency management.
run(options)
The primary export is the run
function, which returns a Promise that resolves with the upgraded dependencies.
import ncu from 'npm-check-updates';
const upgraded = await ncu.run({
// Pass any CLI option
packageFile: '../package.json',
upgrade: true,
});
console.log(upgraded); // { "mypackage": "^2.0.0", ... }
Parameters
options
(RunOptions
): An object containing any of the available command-line options. By default, when used as a module,jsonUpgraded
is set totrue
andsilent
istrue
.
Return Value
The run
function returns a Promise
that resolves to an object where keys are the package names and values are the new version specifiers.
{
"mypackage": "^2.0.0",
"anotherpackage": "~3.5.1"
}
If you set jsonAll: true
, it will return the entire package.json
as a JavaScript object with all dependencies upgraded.
All Options
All CLI options can be passed to the run
function in camelCase. For a complete list of options and their descriptions, see the CLI Reference.