Npm

From G1Joshi/Agent-Skills · View interactive version

Npm is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert npm package manager assistance covering package.json, lockfiles, workspaces (monorepos), scripts, and security audits. Use when managing JavaScript/Node.js dependencies and publishing packages.

How to use this skill

Skill file

npm

npm is the default package manager for Node.js, providing dependency resolution, workspace management, security auditing, and publishing workflows for JavaScript ecosystems.

When to Use

Quick Start

npm init -y
npm install lodash
npm install --save-dev jest

# Monorepo
npm init -w packages/my-lib

Core Concepts

Configuring npm Workspaces in Monorepos

Declaring multi-package structures in root package.json:

{
  "name": "enterprise-monorepo",
  "private": true,
  "workspaces": ["packages/*", "apps/*"],
  "scripts": {
    "build": "npm run build --workspaces --if-present",
    "test": "npm test --workspaces --if-present"
  },
  "overrides": {
    "glob": "^10.4.0",
    "semver": "^7.6.0"
  }
}

Clean Installations & Deterministic Lockfiles

Installing dependencies in continuous integration:

# Clean install adhering strictly to package-lock.json (never mutates lockfile)
npm ci

# Audit dependencies for known CVEs
npm audit --audit-level=high

# Run targeted script across all workspaces
npm run test --workspace=packages/core-utils

Publishing Packages with Cryptographic Provenance

Publishing to the npm registry with supply-chain verification:

# Publish package with Sigstore verifiable provenance
npm publish --access public --provenance

Common Patterns

Monorepo Workspaces Configuration

Problem: Managing shared libraries across multiple internal packages without publishing to external registries.

Solution:

Use native npm workspaces in root package.json:

{
  "name": "my-monorepo",
  "private": true,
  "workspaces": ["packages/*", "apps/*"],
  "scripts": {
    "build": "npm run build --workspaces --if-present",
    "test": "npm test --workspaces"
  }
}

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :----------------------------------------------------- | :----------------------------------------------------------------------- | :-------------------------------------------------------------------------- |

| npm ERR! code ERESOLVE: could not resolve dependency | Peer dependency version conflict. | Run npm install --legacy-peer-deps or align conflicting package versions. |

| npm ERR! code EACCES: permission denied | Installing global packages without permissions on system node directory. | Configure user npm prefix: npm config set prefix ~/.npm-global. |

| package-lock.json out of sync | Dependencies installed with different npm major versions. | Delete node_modules and run npm ci for strict deterministic installs. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.