Packages and Modules

The npm registry contains packages, many of which are also Node modules, or contain Node modules.

Packages

A package is a file or directory that is described by a package.json file. A package must contain a package.json file in order to be published to the npm registry. For more information on creating a package.json file.

Packages can be unscoped or scoped to a user or Org, and scoped packages can be private or public.

Package Format

A package is any of the following:

npm package git URL formats

Git URLs used for npm packages can be formatted in the following ways:

The commit-ish can be any tag, sha, or branch that can be supplied as an argument to git checkout. The default commit-ish is master

Modules

A module is any file or directory in the node_modules directory that can be loaded by the Node.js require() function.

To be loaded by the Node.js require() function, a module must be one of the following:

Since modules are not required to have a package.json file, not all modules are packages. Only modules that have a package.json file are also packages. So if a folder contains package.json can be called either a module or a package. But if the folder doesn't contain any package.json file, it cannot be called a package. It is a module.

Scope

There are billions of packages in the NPM registry. So it is very common that your package name can match with others. To resolve this conflict, you can use scope that allows you to create package with the same name.

The scope name is everything between the @ and the slash:

// npm scope
@npm/package-name
// npmcorp
@npmcorp/package-name

Package Visibility

Your username is always the scope name.

Public Packages

As an npm user or Org member, you can create and publish public packages that anyone can download and use in their own projects.

Private Packages

With npm private packages, you can use the npm registry to host code that is only visible to you and chosen collaborators, allowing you to manage and use private code alongside public code in your projects. To create or use private packages you must be a paid user.

Private packages always have a scope, and scoped packages are private by default.

Package Visibility and Scope

Visibility of npm packages depends on the scope (namespace) in which the package is contained, and the access level (private or public) set for the package.

Public Registry

Scope Access Level Can view and download Can Write(Publish)
Org Private Members of a team in the Org with read access to the package Members of a team in the Org with read and write access to the package
Org Public Everyone Members of a team in the Org with read and write access to the package
User Private The package owner and users who have been granted read access to the package. The package owner and users who have been granted read and write access to the package.
User Public Everyone The package owner and users who have been granted read and write access to the package.
Unscoped Public Everyone The package owner and users who have been granted read and write access to the package.