@reggi/path-to-regexp
@reggi/path-to-regexp
dependabot/npm_and_yarn/main/copy-to-clipboard-4.0.2
dependabot/npm_and_yarn/main/eslint-10.4.0
dependabot/npm_and_yarn/main/npmcli/eslint-config-7.0.0
dependabot/npm_and_yarn/main/proc-log-7.0.0
dependabot/npm_and_yarn/npm_and_yarn-826852524d
dependabot/npm_and_yarn/npm_and_yarn-ab9a7f4bc2
deprecate-totp-2fa
dhei/classic-tokens
gat-bypass-2fa-docs
jpg619/fix-accessibility-content-flow
jpg619/version-bump-tar-2
kartykp/gat-bypass-2fa-docs
kartykp/upgrade-path-to-regex
main
maitxn/version-bump-tar
patch-1
reggi/cache-based-on-version
reggi/dev-engines
reggi/fix-transform-prettier
reggi/overrides
update-search-sensitivity
| 1 | --- |
| 2 | title: About packages and modules |
| 3 | redirect_from: |
| 4 | - /getting-started/packages |
| 5 | --- |
| 6 | |
| 7 | The npm registry contains packages, many of which are also Node modules, or contain Node modules. Read on to understand how they differ and how they interact. |
| 8 | |
| 9 | ## About packages |
| 10 | |
| 11 | 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, see "[Creating a package.json file][pkg-json]". |
| 12 | |
| 13 | Packages can be unscoped or scoped to a user or organization, and scoped packages can be private or public. For more information, see |
| 14 | |
| 15 | - "[About scopes][about-scopes]" |
| 16 | - "[About private packages][private-pkgs]" |
| 17 | - "[Package scope, access level, and visibility][pkg-viz]" |
| 18 | |
| 19 | ### About package formats |
| 20 | |
| 21 | A package is any of the following: |
| 22 | |
| 23 | - a) A folder containing a program described by a `package.json` file. |
| 24 | - b) A gzipped tarball containing (a). |
| 25 | - c) A URL that resolves to (b). |
| 26 | - d) A `<name>@<version>` that is published on the registry with (c). |
| 27 | - e) A `<name>@<tag>` that points to (d). |
| 28 | - f) A `<name>` that has a `latest` tag satisfying (e). |
| 29 | - g) A `git` url that, when cloned, results in (a). |
| 30 | |
| 31 | ### npm package git URL formats |
| 32 | |
| 33 | Git URLs used for npm packages can be formatted in the following ways: |
| 34 | |
| 35 | - `git://github.com/user/project.git#commit-ish` |
| 36 | - `git+ssh://user@hostname:project.git#commit-ish` |
| 37 | - `git+http://user@hostname/project/blah.git#commit-ish` |
| 38 | - `git+https://user@hostname/project/blah.git#commit-ish` |
| 39 | |
| 40 | 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 `HEAD`. |
| 41 | |
| 42 | Installing any package directly from git will not install [git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) or workspaces. |
| 43 | |
| 44 | ## About modules |
| 45 | |
| 46 | A **module** is any file or directory in the `node_modules` directory that can be loaded by the Node.js `require()` function. |
| 47 | |
| 48 | To be loaded by the Node.js `require()` function, a module must be one of the following: |
| 49 | |
| 50 | - A folder with a `package.json` file containing a `"main"` field. |
| 51 | - A JavaScript file. |
| 52 | |
| 53 | <Note> |
| 54 | |
| 55 | **Note:** 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. |
| 56 | |
| 57 | </Note> |
| 58 | |
| 59 | In the context of a Node program, the `module` is also the thing that was loaded _from_ a file. For example, in the following program: |
| 60 | |
| 61 | ``` |
| 62 | var req = require('request') |
| 63 | ``` |
| 64 | |
| 65 | The `req` variable refers to the `request` module returned by the `require()` function. |
| 66 | |
| 67 | [about-scopes]: about-scopes |
| 68 | [private-pkgs]: about-private-packages |
| 69 | [pkg-json]: creating-a-package-json-file |
| 70 | [pkg-viz]: package-scope-access-level-and-visibility |