Class reference
Npm

Npm Reference

Types

NpmPkgOpts

The options for configuring an npm package.

NameTypeRequiredDescription
namestringYesThe name of the package to install
versionstringNoThe version of the package to install
pathstringNoThe path to install the package
globalbooleanYesWhether to install the package globally
silentbooleanYesWhether to print the command output

NpmError

The NpmError class represents an error that occurred during an npm operation.

Properties
NameTypeDescription
messagestringThe error message
namestringThe name of the error

NpmSafeResponse

The response object returned by npm operations.

NameTypeDescription
successbooleanWhether the operation was successful
errorNpmError | nullThe error that occurred (if any)

NpmPackage Class

The NpmPackage class provides methods for interacting with npm packages.

Constructor

The NpmPackage class constructor accepts an NpmPkgOpts object.

import { NpmPackage, NpmPkgOpts } from "@vaibhavvenkat/aacod";
 
const opts: NpmPkgOpts = {
    name: "package-name",
    version: "1.0.0",
    path: "/path/to/install",
    global: true,
    silent: false,
};
 
const npmPackage = new NpmPackage(opts);

Methods

safeInstall(): Promise<NpmSafeResponse>

Safely installs an npm package without throwing an error.

const res: NpmSafeResponse = await npmPackage.safeInstall();
install(): Promise<void>

Installs an npm package.

await npmPackage.install();