NPM (NodeJs Package Manager)

npm is a command-line tool used to manage JavaScript and Node.js packages. It handles dependency installation, version resolution, and package distribution through the public npm registry or private registries.

This reference reflects a usage style oriented toward authorship, maintenance, and long-lived projects rather than rapid experimentation or tutorial scaffolding.

General Commands

Init

Initializes a new npm package by creating a package.json file. This command defines basic package metadata such as name, version, entry point, and license.

npm init

Install

Installs a package and records it as a dependency.

npm install package-name

Install as a development-only dependency. Development dependencies are typically used for tooling, testing, or build steps and are not required at runtime.

npm install package-name -D

Update

Updates installed packages according to version constraints defined in package.json.

npm update

Update dependencies while excluding development dependencies. This is useful for production environments or deployment checks.

npm update --omit=dev

Publishing Commands

Publish

Publishes a package version to the npm registry. This requires authenticated credentials and a valid package.json. Once published, a version becomes immutable in practice and should be treated as permanent.

npm publish --access public

Unpublish

Removes a published package or version from the npm registry.

npm unpublish package-name@version
  • npm restricts unpublishing after a short grace period.
  • Versions depended on by other packages typically cannot be removed.

Deprecate

Marks a package version as deprecated without removing it.

npm deprecate package-name@version "Reason for deprecation"
  • Preserves package availability.
  • Warns users during installation.
  • Is the preferred method for discouraging use of broken, unsafe, or superseded versions

Workspaces

Workspaces allow multiple related packages to be developed and managed within a single repository. They are especially useful for modular systems, shared utilities, and large codebases with internal dependencies. Example package.json workspace configuration

{
    "name": "example-package",
    "workspaces": [
        "packages/*"
    ]
}

Workspaces enable:

  • Local package linking without publishing.
  • Shared dependency resolution.
  • Cleaner monorepo-style development.

Provider