npm-commander
v1.1.1
Published
```markdown # npm-commander
Readme
# npm-commander
A simple utility to run npm commands programmatically.
## Installation
Install `npm-commander` via npm:
```sh
npm install npm-commanderUsage
Synchronous Usage
You can use the synchronous methods provided by npm-commander to run npm commands.
const npmCommander = require('npm-commander');
// Install a package
npmCommander.install('express');
// Uninstall a package
npmCommander.uninstall('express');
// Update a package
npmCommander.update('express');Asynchronous Usage
You can also use the asynchronous methods provided by npm-commander to run npm commands.
const npmCommander = require('npm-commander');
(async () => {
try {
// Install a package
await npmCommander.AsyncFunctions.install('express');
// Uninstall a package
await npmCommander.AsyncFunctions.uninstall('express');
// Update a package
await npmCommander.AsyncFunctions.update('express');
} catch (error) {
console.error(`Error: ${error.message}`);
}
})();Additional Commands
npm-commander also provides additional npm commands.
const npmCommander = require('npm-commander');
// Get npm help
console.log(npmCommander.npm.Help());
// Get npm version
console.log(npmCommander.npm.Version());API
Synchronous Methods
install(packageName, options)uninstall(packageName)update(packageName)
Asynchronous Methods
AsyncFunctions.install(packageName, options)AsyncFunctions.uninstall(packageName)AsyncFunctions.update(packageName)
Additional npm Commands
npm.Help()npm.Version()
Handling Errors
The asynchronous methods throw errors if the npm command fails. Handle errors using try-catch blocks.
const npmCommander = require('npm-commander');
(async () => {
try {
await npmCommander.AsyncFunctions.install('express');
} catch (error) {
console.error(`Error installing package: ${error.message}`);
}
})();Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Links
